aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/path.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh/shrc.d/path.sh')
-rw-r--r--sh/shrc.d/path.sh33
1 files changed, 21 insertions, 12 deletions
diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh
index b6b1820f..a854e148 100644
--- a/sh/shrc.d/path.sh
+++ b/sh/shrc.d/path.sh
@@ -5,15 +5,16 @@ path() {
case $1 in
# List current directories in PATH
- list|'') (
- path=$PATH:
- while [ -n "$path" ] ; do
- dir=${path%%:*}
- path=${path#*:}
- [ -n "$dir" ] || continue
- printf '%s\n' "$dir"
+ list|'')
+ set -- "$PATH":
+ while [ -n "$1" ] ; do
+ case $1 in
+ :*) ;;
+ *) printf '%s\n' "${1%%:*}" ;;
+ esac
+ set -- "${1#*:}"
done
- ) ;;
+ ;;
# Helper function checks directory argument makes sense
_argcheck)
@@ -33,7 +34,9 @@ path() {
# Add a directory at the start of $PATH
insert)
- [ "$#" -eq 2 ] || set -- "$1" "$PWD"
+ if ! [ "$#" -eq 2 ] ; then
+ set -- "$1" "$PWD"
+ fi
path _argcheck "$@" || return
if path check "$2" ; then
printf >&2 'path(): %s: %s already in PATH\n' "$@"
@@ -44,7 +47,9 @@ path() {
# Add a directory to the end of $PATH
append)
- [ "$#" -eq 2 ] || set -- "$1" "$PWD"
+ if ! [ "$#" -eq 2 ] ; then
+ set -- "$1" "$PWD"
+ fi
path _argcheck "$@" || return
if path check "$2" ; then
printf >&2 'path(): %s: %s already in PATH\n' "$@"
@@ -55,7 +60,9 @@ path() {
# Remove a directory from $PATH
remove)
- [ "$#" -eq 2 ] || set -- "$1" "$PWD"
+ if ! [ "$#" -eq 2 ] ; then
+ set -- "$1" "$PWD"
+ fi
path _argcheck "$@" || return
if ! path check "$2" ; then
printf >&2 'path(): %s: %s not in PATH\n' "$@"
@@ -107,7 +114,9 @@ path() {
# Check whether a directory is in PATH
check)
path _argcheck "$@" || return
- [ "$#" -eq 2 ] || set -- "$1" "$PWD"
+ if ! [ "$#" -eq 2 ] ; then
+ set -- "$1" "$PWD"
+ fi
case :$PATH: in
*:"$2":*) return 0 ;;
esac