2 # avoiding bashisms so it can be used in edge cases where I don't have bash,
3 # however, I'm not super confident that I've avoided them all
7 local help="usage: path_add [options] PATH
9 --end: adds to end of path, which will give it lowest priority
10 --ifexists: add to path only if the directory exists"
11 local found x y z ifexists end loop newpath
15 # portable substring matching is ugly http://mywiki.wooledge.org/BashFAQ/041
19 if [ "$1" = --end ]; then
21 elif [ "$1" = --force ]; then
23 elif [ "$1" = --help ]; then
35 # build up the path without the components we want to add
38 if [ "$x" = "$y" ]; then
45 if [ ! "$newpath" ]; then
56 x
="$(readlink -f "$x")"
57 if $force ||
[ -d "$x" ]; then
58 if [ ! "$PATH" ]; then