make path_add more correct for dash
authorIan Kelling <ian@iankelling.org>
Fri, 30 May 2014 17:26:10 +0000 (10:26 -0700)
committerIan Kelling <ian@iankelling.org>
Thu, 4 May 2017 23:40:14 +0000 (16:40 -0700)
.bashrc
path_add-function

diff --git a/.bashrc b/.bashrc
index 5b4c3d102a87cd05aad2dfa66dc6b5a9190bc989..b8b286116ede7d64a5d9a4cac07de4d8aa702e32 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -54,31 +54,31 @@ CDPATH=.:/a
 # 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.
 shopt -s extglob
 #include .files when globbing.
 shopt -s dotglob
+#but ignore files name . and ..
+#those are default when this is set to anything, so we just set it to one of them
+export GLOBIGNORE=.
 
-# disabled because it is broken with bash_completion package. It is a known bug they hope to fix.
-# When a glob expands to nothing, make it an empty string instead of the literal characters.
-# shopt -s nullglob
+# broken with bash_completion package. Saw a bug for this once. Don't anymore.
+# still broken in wheezy
+# still buggered in latest stable from the web, version 2.1
+# perhaps its fixed in newer git version, which fails to make for me
+#shopt -s nullglob
 
 # make tab on an empty line do nothing
 shopt -s no_empty_cmd_completion
 
-
 # advanced completion
 # http://bash-completion.alioth.debian.org/
-# i was using the git version for a while for a bug fix.
-# it's made it into distros now
-# usually this is sourced by the system already,
-# but I check just incase
+# might be sourced by the system already, but I've noticed it not being sourced before
 if ! type _init_completion &> /dev/null && [[ -r "/usr/share/bash-completion/bash_completion" ]]; then
     . /usr/share/bash-completion/bash_completion
 fi
 
+
 # fix spelling errors for cd, only in interactive shell
 shopt -s cdspell
 # append history instead of overwritting it
@@ -146,7 +146,7 @@ unset HISTIGNORE
 
 export BC_LINE_LENGTH=0
 
-path_add /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
+path_add --ifexists /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
 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
index 6f06ed9b2c95dba2766fda574750ca04b3737759..428e2ecabc2faef3359efcb6cd61783ae32ae50b 100644 (file)
@@ -3,17 +3,25 @@
 # --start adds to start of path, which will give it highest priority
 # --ifexists will add to path only if the directory exists
 path_add() {
-    local found x y z
-    local ifexists start
+    local found x y z ifexists start loop
     ifexists=false
     start=false
-    while [ "$1" = --* ]; do
-        if [ "$1" = --start ]; then
-            start=true
-        elif [ "$1" = --ifexists ]; then
-            ifexists=true
-        fi
-        shift
+    loop=true
+    # portable substring matching is ugly http://mywiki.wooledge.org/BashFAQ/041
+    while $loop; do
+        case $1 in
+            --*)
+                if [ "$1" = --start ]; then
+                    start=true
+                elif [ "$1" = --ifexists ]; then
+                    ifexists=true
+                fi
+                shift
+                ;;
+            *)
+                loop=false
+                ;;
+        esac
     done
     for x in "$@"; do
         found=false
@@ -23,7 +31,7 @@ path_add() {
         done
         unset IFS
         if ! $found; then
-            if ! $ifexists || [ -d $x ]; then
+            if ! $ifexists || [ -d "$x" ]; then
                 if [ ! "$PATH" ]; then
                     PATH="$x"
                 elif $start; then