mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
turn have
, has
, and maybesudo
into one-liners
This commit is contained in:
parent
eb31cf5450
commit
2b0c642512
1 changed files with 3 additions and 11 deletions
14
home/shrc
14
home/shrc
|
@ -8,18 +8,10 @@ fi
|
||||||
|
|
||||||
# {{{1 utilities
|
# {{{1 utilities
|
||||||
|
|
||||||
have() {
|
have() { if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi; } 2>/dev/null
|
||||||
if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi
|
has() { have "$@"; } >/dev/null
|
||||||
} 2>/dev/null
|
|
||||||
has() {
|
|
||||||
have "$@"
|
|
||||||
} >/dev/null
|
|
||||||
|
|
||||||
if has sudo; then
|
has sudo && maybesudo() { sudo "$@"; } || maybesudo() { maybesudo_ "$@"; }
|
||||||
maybesudo() { sudo "$@"; }
|
|
||||||
else
|
|
||||||
maybesudo() { maybesudo_ "$@"; }
|
|
||||||
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.
|
||||||
[ $# = 1 ] || { printf >&2 'ADDPATH: expected exactly 1 argument, got %s\n' $#; return 64; }
|
[ $# = 1 ] || { printf >&2 'ADDPATH: expected exactly 1 argument, got %s\n' $#; return 64; }
|
||||||
|
|
Loading…
Add table
Reference in a new issue