# 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.
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
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
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