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
|
||||
|
||||
ADDPATH() { ### @- append a directory to `$PATH` if it isn't already present.
|
||||
if [ "$1" != "${1#[A-Z]:\\}" ]; then
|
||||
set -- "$(cygpath -u "$1")"
|
||||
if [ $# -ne 1 ]; then
|
||||
printf 'ADDPATH: expected exactly 1 argument, got %s\n' $# >&2
|
||||
return 2
|
||||
fi
|
||||
if [ "$1" != "${1#[A-Z]:\\}" ]; then
|
||||
set -- "$(cygpath -u "$1" || printf '%s\n' "$1")"
|
||||
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
|
||||
local new="$(readlink -f "$1")"
|
||||
if [ ! -d "$new" ]; then
|
||||
printf 'ADDPATH: path does not exist: %s\n' "$1" >&2
|
||||
return 1
|
||||
fi
|
||||
if [ ${#PATH} = 0 ]; then
|
||||
PATH="$1"
|
||||
return 0
|
||||
fi
|
||||
case ":$PATH:" in
|
||||
(*":$new:"*) :;;
|
||||
(*) export PATH="$PATH:$new";;
|
||||
(*":$1:"*) :;;
|
||||
(*) PATH="$PATH:$1";;
|
||||
esac
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue