fix debconf warning mesages in emacs
[distro-setup] / .bashrc
diff --git a/.bashrc b/.bashrc
index 263e6aabb59fbf7004f7d544baf4f310a51adfcc..e8651b544b641d15e6836f43170fe7f5630450d6 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -29,8 +29,7 @@ for x in $HOME/bin/bash-programs-by-ian/repos/*/*-function; do
     source "$x"
 done
 
-# so I can share my bashrc
-source $HOME/bin/bash_private
+source $HOME/bin/bash_private # so I can share my bashrc
 source $HOME/path_add-function
 
 
@@ -42,6 +41,10 @@ source $HOME/path_add-function
 
 CDPATH=.:/a
 
+# remove gnome keyring warning messages
+# there is probably a more proper way, but I didn't find any easily on google
+unset GNOME_KEYRING_CONTROL
+
 path_add /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
 
 #use extra globing features. See man bash, search extglob.
@@ -80,7 +83,17 @@ if [[ $- == *i* ]]; then
     if [[ $INSIDE_EMACS ]]; then
         bind 'set horizontal-scroll-mode on'
         bind 'set print-completions-horizontally on'
+        export PAGER=cat
+        export MANPAGER=cat
         stty echo
+        # debconf occasionally spews messages about wanting to initialize dialog
+        # and falling back to readline, since our terminal is dumb, then does nothing,
+        # This is a long standing bug. Here is the fix.
+        if [[ $DISPLAY ]]; then
+            export DEBIAN_FRONTEND=gnome
+        else
+            export DEBIAN_FRONTEND=readline
+        fi
     else
         stty werase undef lnext undef stop undef start undef
         # terminal keys: C-c, C-z. the rest defined by stty -a are, at least in
@@ -105,12 +118,14 @@ PS4='$LINENO+ '
 HISTFILESIZE=
 # max commands 1 session can append to history
 HISTSIZE=100000
+# my history size limit based on lines
+HISTFILELINES=1000000
 # this needs to be different from the derault because
 # default HISTFILESIZE is 500 and could clobber our history
 HISTFILE=$HOME/.bh
 HISTTIMEFORMAT="%I:%M %p %m/%d "
-# duplicate, single letter, and space prepended commands do not go in history
-HISTIGNORE="&:?: *"
+# consecutive duplicate lines don't go in history
+HISTIGNORE="&"
 
 export BC_LINE_LENGTH=0
 
@@ -119,7 +134,7 @@ path_add $HOME/bin/bash-programs-by-ian/utils
 # note, if I use a machine I don't want files readable by all users, set
 # umask 077  # If fewer than 4 digits are entered, leading zeros are assumed
 
-
+C_DEFAULT_DIR=/a
 
 
 
@@ -196,13 +211,17 @@ t() {
 }
 
 
+if type ack-grep >/dev/null 2>&1; then
+    alias ack=ack-grep
+fi
+
 
 gr() {
     grep -i --binary-files=without-match --color=auto "$@"
 }
 
-gr() {
-    gr -r "$@"
+grr() {
+    grep -ri --binary-files=without-match --color=auto "$@"
 }
 
 
@@ -403,23 +422,34 @@ despace() {
 }
 
 # force symbolic link creation.
-# trash-put any existing targets,
-# then send all arguments to ln -s
+# trash-put any existing files where links would be created.
+# mkdir -p the directory containing the link(s) if needed.
+# then do ln -s -- "$@"
 lnf() {
+    if [[ $# -gt 2 && ! -d ${!#} ]]; then
+        mkdir -p "${!#}"
+    fi
     if [[ $# -gt 1 && -d ${!#} ]]; then
         local oldcwd=$PWD
         cd ${!#} # last arg
         for x in "${@:1:$(($#-1))}"; do # all but last arg
-            # a broken symlink will fail the "exists" -e test
-            [[ -e "${x##*/}" || -L "${x##*/}" ]] && trash-put "${x##*/}"
+            # remove any trailing slashes
+            x="${x%%+(/)}"
+            # remove any leading directory components
+            x="${x##*/}"
+            te "$x" && trash-put "$x"
         done
         cd "$oldcwd"
     elif [[ $# -eq 2 ]]; then
-        [[ -e "$2" || -L "$2" ]] && rm "$2"
+        if te "$2"; then
+            trash-put "$2"
+        elif [[ ! -d $(getdir "$2") ]]; then
+            mkdir -p $(getdir "$2")
+        fi
     else
-        [[ -e "${1##*/}" || -L "${1##*/}" ]] && rm "${1##*/}"
+        te "${1##*/}" && rm "${1##*/}"
     fi
-    ln -s "$@"
+    ln -s -- "$@"
 }
 
 
@@ -475,7 +505,14 @@ else
 fi
 
 
-
+# test existence
+te() {
+    local ret=0
+    for x in "$@"; do
+        [[ -e "$x" || -L "$x" ]] || ret=1
+    done
+    return $ret
+}
 
 
 # fix root file ownership for FILE argument.
@@ -487,7 +524,7 @@ perm_fix() {
        [[ -e $1 ]] || touch $1
        if [[ $(stat -c "%u" "$1") == 0 ]] ; then
 
-           argdir=$(dirstrip "$1")
+           argdir=$(getdir "$1")
            if [[ $(stat -c "%u" "$argdir") != 0 ]] ; then
                if ! chown "--reference=$argdir" "$1"; then
                    echo failed to fix bad ownership file permissons
@@ -679,18 +716,19 @@ 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
-    if ! [[ -w $HISTFILE ]] || ! [[ -w ${HISTFILE}_archive ]]; then
-       echo "error: a history file is not writable."
-       return 1
-    fi
+    for x in $HISTFILE ${HISTFILE}_archive; do
+        if [[ -e $x && ! -w $x ]]; then
+            echo "error: history file $x is not writable."
+           return 1
+        fi
+    done
     history -w
     if [[ $1 ]]; then
        max_lines=$(($1 * 2)) # 2 lines for every history command
     else
-       max_lines=1000000
+       max_lines=$HISTFILELINES
     fi
     linecount=$(wc -l < $HISTFILE)
     linecount=${linecount:-0}
@@ -699,17 +737,14 @@ hl() { # history limit. Write extra history to archive file.
        tempfile=$(mktemp)
        [[ $tempfile ]] || { echo mktemp failed; return 1; }
        head -$prune_lines $HISTFILE >> ${HISTFILE}a \
-           && sed -e "1,${prune_lines}d"  $HISTFILE > $tempfile \
-           && mv $tempfile $HISTFILE
+           && sed -ie "1,${prune_lines}d"  $HISTFILE
     fi
     perm_fix $HISTFILE
     perm_fix ${HISTFILE}_archive
-    history -c
-    history -r
 }
-# run hl when bash exits normally
-trap hl EXIT
 
+# commands to run when bash exits normally
+trap "hl; smh" EXIT
 
 
 # temporary variables to test colorization