mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
rewrite ADDPATH to handle more stuff
This commit is contained in:
parent
49f05a058d
commit
021aa8c0ba
1 changed files with 21 additions and 7 deletions
28
home/shrc
28
home/shrc
|
@ -22,17 +22,31 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ADDPATH() { ### @- append a directory to `$PATH` if it isn't already present.
|
ADDPATH() { ### @- append a directory to `$PATH` if it isn't already present.
|
||||||
if [ "$1" != "${1#[A-Z]:\\}" ]; then
|
if [ $# -ne 1 ]; then
|
||||||
set -- "$(cygpath -u "$1")"
|
printf 'ADDPATH: expected exactly 1 argument, got %s\n' $# >&2
|
||||||
|
return 2
|
||||||
fi
|
fi
|
||||||
local new="$(readlink -f "$1")"
|
if [ "$1" != "${1#[A-Z]:\\}" ]; then
|
||||||
if [ ! -d "$new" ]; then
|
set -- "$(cygpath -u "$1" || printf '%s\n' "$1")"
|
||||||
printf 'ADDPATH: path does not exist: %s\n' "$1" >&2
|
fi
|
||||||
|
set -- "$(readlink -f "$1")" "$1"
|
||||||
|
if ! [ -d "$1" ]; then
|
||||||
|
if [ -e "$1" ]; then
|
||||||
|
printf 'ADDPATH: not a directory: %s\n' "$1" >&2
|
||||||
|
else
|
||||||
|
set -- "$2" "$( (true <"$2") 2>&1)"
|
||||||
|
[ -z "$ZSH_VERSION" ] || 2="${2%: *}"
|
||||||
|
printf 'ADDPATH: %s: %s\n' "$1" "${2##*: }" >&2
|
||||||
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
if [ ${#PATH} = 0 ]; then
|
||||||
|
PATH="$1"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
case ":$PATH:" in
|
case ":$PATH:" in
|
||||||
(*":$new:"*) :;;
|
(*":$1:"*) :;;
|
||||||
(*) export PATH="$PATH:$new";;
|
(*) PATH="$PATH:$1";;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue