aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/path.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-14 13:14:00 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-14 13:14:00 +1300
commite0ff7ac01d6439d826ff9ef6f134a7638ade714f (patch)
tree781004065fefcbfd8e543a61de3d168383e71bde /sh/shrc.d/path.sh
parentMerge branch 'release/v3.1.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-3.2.0.tar.gz (sig)
dotfiles-3.2.0.zip
Merge branch 'release/v3.2.0'v3.2.0
* release/v3.2.0: Bump VERSION Refactor some conditionals Factor out zsh ENV hack into one file Refactor "path list" not to require a subshell Correct completion for deep pass(1) directories Move filetype.vim helper funcs into autoload Fix a local var name in openssl(1ssl) completion Correct a variable ref in openssl(1ssl) completion Disable shellcheck rules for missed definition Add filenames treatment to mex(1df) completion Remove unneeded declaration Refactor some completions to avoid loops Remove unneeded stdout redirect Remove unneeded semicolon from sh "for VAR ; do" Substitute bad `continue` for `return` Add actual completion matching to git completion Apply much simpler completion to Git
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