mirror of
https://github.com/notwa/rc
synced 2024-05-18 09:53:22 -07:00
rename has
to have
; has
is now silent
i'm not sure why i was overengineering this function so much, but the code i deleted might still come in handy someday.
This commit is contained in:
parent
45501f7e73
commit
444c34f98e
28
home/-shrc
28
home/-shrc
|
@ -4,24 +4,14 @@
|
|||
|
||||
# {{{1 utilities
|
||||
|
||||
has() ( # hardcoded here for convenience. refer to ~/sh/has for documentation.
|
||||
if [ "${1:-/}" = "${1#*[!A-Za-z_-]}" ]; then
|
||||
if [ "$FANCY" = 0 ] || [ "${1:-/}" = "${1#-}" ]; then
|
||||
alias "$1"=
|
||||
unalias -- "$1"
|
||||
fi
|
||||
if [ "$FANCY" = 1 ]; then
|
||||
eval -- "$1() (:)"
|
||||
unset -f -- "$1"
|
||||
elif [ "${1:-/}" = "${1#*-}" ]; then
|
||||
eval "$1() (:)"
|
||||
unset -f -- "$1"
|
||||
fi
|
||||
fi
|
||||
which -- "$1" >/dev/null 2>&1 && which -- "$1"
|
||||
)
|
||||
have() {
|
||||
if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi
|
||||
} 2>/dev/null
|
||||
has() {
|
||||
have "$@"
|
||||
} >/dev/null
|
||||
|
||||
if has sudo >/dev/null; then
|
||||
if has sudo; then
|
||||
maybesudo() { sudo "$@"; }
|
||||
else
|
||||
maybesudo() { maybesudo_ "$@"; }
|
||||
|
@ -78,7 +68,7 @@ if [ "$FANCY" -eq 1 ]; then
|
|||
alias grep='grep --color=auto'
|
||||
alias ls='ls --color=auto'
|
||||
alias lr="lr -G"
|
||||
#alias make="$(has colormake || has make)"
|
||||
#alias make="$(have colormake || have make)"
|
||||
fi
|
||||
|
||||
# just flags {{{2
|
||||
|
@ -134,7 +124,7 @@ alias eacp='ea copy' ### @- invoke [`ea copy`.](#ea)
|
|||
alias earm='ea delete' ### @- invoke [`ea delete`.](#ea)
|
||||
|
||||
### @ ll - list files verbosely, fancily, ordered, but not recursively.
|
||||
if has lr >/dev/null; then
|
||||
if has lr; then
|
||||
alias ll='ify less lr -1lshGG -o tev'
|
||||
else
|
||||
alias ll='ify less ls -lAX --group-directories-first --color=force'
|
||||
|
|
32
sh/has
32
sh/has
|
@ -4,34 +4,8 @@
|
|||
# YES_DASH
|
||||
# YES_ASH
|
||||
|
||||
has() ( ### @- print the result of `which` if the program is found, else simply return 1.
|
||||
### ```
|
||||
### export SOLVER="$(has kissat || has picosat || has cadical || has minisat)"
|
||||
### ```
|
||||
fancy=0
|
||||
[ -z "$ZSH_VERSION" ] && [ -z "$BASH_VERSION" ] || fancy=1
|
||||
|
||||
if [ "${1:-/}" = "${1#*[!A-Za-z_-]}" ]; then # has a simple name?
|
||||
# only ash and dash support aliases beginning with hyphens.
|
||||
# forcefully unalias it (regardless of if it even was an alias):
|
||||
if [ $fancy = 0 ] || [ "${1:-/}" = "${1#-}" ]; then
|
||||
alias "$1"=
|
||||
unalias -- "$1"
|
||||
fi
|
||||
|
||||
# only bash and zsh support function names containing hyphens.
|
||||
# forcefully unset it (regardless of if it even was a function):
|
||||
if [ "$FANCY" = 1 ]; then
|
||||
eval -- "$1() (:)"
|
||||
unset -f -- "$1"
|
||||
elif [ "${1:-/}" = "${1#*-}" ]; then
|
||||
eval "$1() (:)"
|
||||
unset -f -- "$1"
|
||||
fi
|
||||
fi
|
||||
|
||||
which -- "$1" >/dev/null 2>&1 && which -- "$1"
|
||||
) # this uses parentheses instead of braces so that the function is always run
|
||||
# in a subshell. otherwise, the user's aliases and functions may be overwritten.
|
||||
has() { ### @- [`have`,](#have) silently.
|
||||
if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi
|
||||
} >/dev/null 2>/dev/null
|
||||
|
||||
[ -n "${preload+-}" ] || has "$@"
|
||||
|
|
14
sh/have
Normal file
14
sh/have
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
# YES_ASH
|
||||
|
||||
have() { ### @- print the result of `which` if the program is found, else simply return 1.
|
||||
### ```
|
||||
### export SOLVER="$(have kissat || have picosat || have cadical || have minisat)"
|
||||
### ```
|
||||
if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi
|
||||
} 2>/dev/null
|
||||
|
||||
[ -n "${preload+-}" ] || have "$@"
|
Loading…
Reference in New Issue
Block a user