prompt bug fix
[distro-setup] / .bashrc
diff --git a/.bashrc b/.bashrc
index ae0da0ae4d11bce5a50a3cde6c35899179571c02..3484db419a8711ecee8de73e02146346583518fb 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -9,17 +9,24 @@
 # 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.
+# In a private file, i have aliases for if $- == *i*, ssh -t, else ssh.
+
+[[ $- != *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 +95,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 +113,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
@@ -172,7 +179,7 @@ mkdir() {
 alias d='builtin bg'
 complete -A stopped -P '"%' -S '"' d
 
-alias his='history'
+alias hi='history'
 
 
 # note: gksudo is recommended for X apps because it does not set the
@@ -497,10 +504,16 @@ else
         fi
     }
     pf() {
+        # scratch a very annoying itch.
+        # package description width as wide as the screen, and package name field small
+        # aptitude manual can't figure out how wide emacs terminal is,
+        # of course it doesn't consult the $COLUMNS variable...
+        # and in a normal terminal, it makes the package name field ridiculously big
+        # also, remove that useless dash before the description
         if [[ $EUID == 0 ]]; then
-            aptitude search "$@"
+            aptitude -F "%c%a%M %p %$((COLUMNS - 30))d" -w $COLUMNS search "$@"
         else
-            sudo aptitude search "$@"
+            sudo aptitude -F "%c%a%M %p %$((COLUMNS - 30))d" -w $COLUMNS search "$@"
         fi
     }
 fi
@@ -717,17 +730,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
@@ -883,7 +896,7 @@ if [[ $- == *i* ]]; then
                ps_color="$(get_term_color bold green)"
             fi
         fi
-        PS1="${PS1/%!(*[wW]*)}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
+        PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
     }
     PROMPT_COMMAND=prompt_command
 fi