From eb01be8f06affc8c42b3835a96ddc9e78de0315d Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 13 May 2014 04:44:29 -0700 Subject: [PATCH] fix history and ssh --- .bashrc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.bashrc b/.bashrc index ae0da0a..f7af595 100644 --- a/.bashrc +++ b/.bashrc @@ -9,17 +9,22 @@ # Normally, this file is not sourced when a script is run, and it would be much # better and more consistent if that also happened when when running a script # over ssh. so here we test for conditions of a script under ssh and return if -# so. we can override with ssh -t which sets $SSH_TTY, which we can detect +# so. we can override with ssh -t which sets $SSH_TTY, which we can detect +# But inside a script, ssh -t won't work, because we aren't using a tty at all. +# So we need something else. Command lines and env variables sent across ssh are strictly limited. +# We could override an obscure unused LC_var, like telephone, or we could transfer a file. +# But I choose to set SendEnv and AcceptEnv ssh vars for BASH_LOGIN_SHELL. + +[[ $- != *i* && ! $SSH_CONNECTION ]] && export BASH_LOGIN_SHELL=true if [[ $SSH_CONNECTION ]] \ && [[ $- == *c* ]] \ && [[ ! $SSH_TTY ]] \ + && [[ ! $BASH_LOGIN_SHELL == true ]] \ && [[ $- != *i* ]]; then return fi -# Side note on ssh. Command lines and env variables sent across ssh are strictly limited. -# If we did want to easily pass info, we could override an obscure unused LC_var -# Or we could set SendEnv and AcceptEnv ssh vars, or we could transfer a file. +# Side note on ssh. @@ -88,10 +93,6 @@ if [[ $INSIDE_EMACS ]]; then export MANPAGER=cat # for readline-complete.el stty echo -else - # terminal keys: C-c, C-z. the rest defined by stty -a are, at least in - # gnome-terminal, overridden by bash, or disabled by the system - stty werase undef lnext undef stop undef start undef fi @@ -110,6 +111,10 @@ if [[ $- == *i* ]]; then bind '"\eOc": shell-forward-word' bind '"\eOd": shell-backward-word' fi + # terminal keys: C-c, C-z. the rest defined by stty -a are, at least in + # gnome-terminal, overridden by bash, or disabled by the system + stty werase undef lnext undef stop undef start undef + fi fi @@ -717,17 +722,17 @@ complete -F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr hl() { # history limit. Write extra history to archive file. - local max_lines linecount tempfile + local max_lines linecount tempfile prune_lines local harchive="${HISTFILE}_archive" for x in "$HISTFILE" "$harchive"; do if [[ ! $x || ! -w $x || $(stat -c "%u" "$x") != $EUID ]]; then - echo "error in hl: history file $x no good." + echo "error in hl: history file $x no good" return 1 fi done - history -w + history -a # save history max_lines=$HISTFILELINES - [[ $max_lines ]] || { echo "error in hl: failed to get max line count"; return 1; } + [[ $max_lines =~ ^[0-9]+$ ]] || { echo "error in hl: failed to get max line count"; return 1; } linecount=$(wc -l < $HISTFILE) # pipe so it doesn't output a filename [[ $linecount =~ ^[0-9]+$ ]] || { echo "error in hl: wc failed"; return 1; } if (($linecount > $max_lines)); then -- 2.30.2