a few bug fixes
authorIan Kelling <ian@iankelling.org>
Wed, 30 Apr 2014 21:54:58 +0000 (14:54 -0700)
committerIan Kelling <ian@iankelling.org>
Thu, 4 May 2017 23:40:14 +0000 (16:40 -0700)
.bashrc

diff --git a/.bashrc b/.bashrc
index 263e6aabb59fbf7004f7d544baf4f310a51adfcc..e7c4aaa0045257aa9c6b2856de1bce78eb24e75e 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.
@@ -119,7 +122,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
 
 
 
@@ -201,8 +204,8 @@ gr() {
     grep -i --binary-files=without-match --color=auto "$@"
 }
 
-gr() {
-    gr -r "$@"
+grr() {
+    grep -ri --binary-files=without-match --color=auto "$@"
 }
 
 
@@ -403,23 +406,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 +489,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 +508,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,13 +700,14 @@ 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
@@ -707,9 +729,9 @@ hl() { # history limit. Write extra history to archive file.
     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