From: Ian Kelling Date: Fri, 30 May 2014 17:26:10 +0000 (-0700) Subject: make path_add more correct for dash X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=commitdiff_plain;h=fd19384f0fa703aacbe21d0bf1f086186bcd5936 make path_add more correct for dash --- diff --git a/.bashrc b/.bashrc index 5b4c3d1..b8b2861 100644 --- 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 diff --git a/path_add-function b/path_add-function index 6f06ed9..428e2ec 100644 --- a/path_add-function +++ b/path_add-function @@ -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