aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-25 21:05:19 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-25 21:05:19 +1300
commitcc5634afcf6590f947da526f408d1985fffeb16d (patch)
tree03b67d6c4fc4d54b5add6244b1efebc546f59432 /sh/shrc.d
parentMerge branch 'master' into port/bsd/freebsd (diff)
parentAdd "pop" and "shift" methods to path() (diff)
downloaddotfiles-cc5634afcf6590f947da526f408d1985fffeb16d.tar.gz
dotfiles-cc5634afcf6590f947da526f408d1985fffeb16d.zip
Merge branch 'master' into port/bsd/freebsd
Diffstat (limited to 'sh/shrc.d')
-rw-r--r--sh/shrc.d/path.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh
index 23eec75b..2759e11f 100644
--- a/sh/shrc.d/path.sh
+++ b/sh/shrc.d/path.sh
@@ -79,6 +79,40 @@ path() {
PATH=${PATH%%:}
;;
+ # Remove the first directory in $PATH
+ shift)
+ case $PATH in
+ '')
+ printf >&2 'path(): %s: PATH is empty!\n' "$@"
+ return 1
+ ;;
+ *:*)
+ PATH=${PATH#*:}
+ ;;
+ *)
+ # shellcheck disable=SC2123
+ PATH=
+ ;;
+ esac
+ ;;
+
+ # Remove the last directory in $PATH
+ pop)
+ case $PATH in
+ '')
+ printf >&2 'path(): %s: PATH is empty!\n' "$@"
+ return 1
+ ;;
+ *:*)
+ PATH=${PATH%:*}
+ ;;
+ *)
+ # shellcheck disable=SC2123
+ PATH=
+ ;;
+ esac
+ ;;
+
# Check whether a directory is in PATH
check)
path _argcheck "$@" || return
@@ -103,6 +137,10 @@ USAGE:
Add directory DIR (default $PWD) to the end of PATH
path remove [DIR]
Remove directory DIR (default $PWD) from PATH
+ path shift
+ Remove the first directory from PATH
+ path pop
+ Remove the last directory from PATH
path check [DIR]
Return whether directory DIR (default $PWD) is a component of PATH
path help