1
0
Fork 0
mirror of synced 2024-12-25 23:43:20 -05:00

Use zsh style tests for empty vars

This commit is contained in:
ℳichiel ℛoos 2017-05-10 21:30:47 +02:00
parent 4ad8f8db8e
commit 393bd00114
No known key found for this signature in database
GPG key ID: B8443AC4B9C7BBC3
4 changed files with 22 additions and 22 deletions

View file

@ -39,7 +39,7 @@ unsetopt HUP
unsetopt CHECK_JOBS unsetopt CHECK_JOBS
# Set less or more as the default pager. # Set less or more as the default pager.
if [[ -z ${PAGER} ]]; then if (( ${+PAGER} )); then
if (( ${+commands[less]} )); then if (( ${+commands[less]} )); then
export PAGER=less export PAGER=less
else else

View file

@ -41,20 +41,20 @@ case $1 in
fi fi
# set default options # set default options
[ -z "$_FASD_DATA" ] && _FASD_DATA="$HOME/.fasd" (( "${+_FASD_DATA}" )) && _FASD_DATA="$HOME/.fasd"
[ -z "$_FASD_BLACKLIST" ] && _FASD_BLACKLIST="--help" (( "${+_FASD_BLACKLIST}" )) && _FASD_BLACKLIST="--help"
[ -z "$_FASD_SHIFT" ] && _FASD_SHIFT="sudo busybox" (( "${+_FASD_SHIFT}" )) && _FASD_SHIFT="sudo busybox"
[ -z "$_FASD_IGNORE" ] && _FASD_IGNORE="fasd ls echo" (( "${+_FASD_IGNORE}" )) && _FASD_IGNORE="fasd ls echo"
[ -z "$_FASD_SINK" ] && _FASD_SINK=/dev/null (( "${+_FASD_SINK}" )) && _FASD_SINK=/dev/null
[ -z "$_FASD_TRACK_PWD" ] && _FASD_TRACK_PWD=1 (( "${+_FASD_TRACK_PWD}" )) && _FASD_TRACK_PWD=1
[ -z "$_FASD_MAX" ] && _FASD_MAX=2000 (( "${+_FASD_MAX}" )) && _FASD_MAX=2000
[ -z "$_FASD_BACKENDS" ] && _FASD_BACKENDS=native (( "${+_FASD_BACKENDS}" )) && _FASD_BACKENDS=native
[ -z "$_FASD_FUZZY" ] && _FASD_FUZZY=2 (( "${+_FASD_FUZZY}" )) && _FASD_FUZZY=2
[ -z "$_FASD_VIMINFO" ] && _FASD_VIMINFO="$HOME/.viminfo" (( "${+_FASD_VIMINFO}" )) && _FASD_VIMINFO="$HOME/.viminfo"
[ -z "$_FASD_RECENTLY_USED_XBEL" ] && \ (( "${+_FASD_RECENTLY_USED_XBEL}" )) && \
_FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel" _FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel"
if [ -z "$_FASD_AWK" ]; then if (( "${+_FASD_AWK}" )); then
# awk preferences # awk preferences
local awk; for awk in mawk gawk original-awk nawk awk; do local awk; for awk in mawk gawk original-awk nawk awk; do
$awk "" && _FASD_AWK=$awk && break $awk "" && _FASD_AWK=$awk && break
@ -125,7 +125,7 @@ case $1 in
# add current pwd if the option is set # add current pwd if the option is set
[ "$_FASD_TRACK_PWD" = "1" -a "$PWD" != "$HOME" ] && paths="$paths|$PWD" [ "$_FASD_TRACK_PWD" = "1" -a "$PWD" != "$HOME" ] && paths="$paths|$PWD"
[ -z "${paths##\|}" ] && return # stop if we have nothing to add (( "${+paths##\|}" )) && return # stop if we have nothing to add
# maintain the file # maintain the file
local tempfile local tempfile
@ -312,12 +312,12 @@ $(fasd --backend $each)"
while [ "$1" ]; do case $1 in while [ "$1" ]; do case $1 in
--complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;; --complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;;
--query|--add|--delete|-A|-D) fasd "$@"; return $?;; --query|--add|--delete|-A|-D) fasd "$@"; return $?;;
--version) [ -z "$comp" ] && echo "1.0.1" && return;; --version) (( "${+comp}" )) && echo "1.0.1" && return;;
--) while [ "$2" ]; do shift; fnd="$fnd $1"; last="$1"; done;; --) while [ "$2" ]; do shift; fnd="$fnd $1"; last="$1"; done;;
-*) local o="${1#-}"; while [ "$o" ]; do case $o in -*) local o="${1#-}"; while [ "$o" ]; do case $o in
s*) local show=1;; s*) local show=1;;
l*) local lst=1;; l*) local lst=1;;
i*) [ -z "$comp" ] && local interactive=1 show=1;; i*) (( "${+comp}" )) && local interactive=1 show=1;;
r*) local mode=rank;; r*) local mode=rank;;
t*) local mode=recent;; t*) local mode=recent;;
e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e" e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e"
@ -343,7 +343,7 @@ $(fasd --backend $each)"
f*) local typ=f;; f*) local typ=f;;
R*) local r=r;; R*) local r=r;;
[0-9]*) local _fasd_i="$o"; break;; [0-9]*) local _fasd_i="$o"; break;;
h*) [ -z "$comp" ] && echo "fasd [options] [query ...] h*) (( "${+comp}" )) && echo "fasd [options] [query ...]
[f|a|s|d|z] [options] [query ...] [f|a|s|d|z] [options] [query ...]
options: options:
-s list paths with scores -s list paths with scores
@ -376,7 +376,7 @@ fasd [-A|-D] [paths ...]
fi;; fi;;
esac esac
local R; [ -z "$r" ] && R=r || R= # let $R be the opposite of $r local R; (( "${+r}" )) && R=r || R= # let $R be the opposite of $r
fnd="${fnd# }" fnd="${fnd# }"
local res local res
@ -407,7 +407,7 @@ fasd [-A|-D] [paths ...]
fi fi
if [ "$res" ]; then if [ "$res" ]; then
fasd --add "$res" fasd --add "$res"
[ -z "$exec" ] && exec='printf %s\n' (( "${+exec}" )) && exec='printf %s\n'
$exec "$res" $exec "$res"
fi fi
;; ;;

View file

@ -6,7 +6,7 @@ fasd_cd() {
fasd "$@" fasd "$@"
else else
local _fasd_ret="$(fasd -e 'printf %s' "$@")" local _fasd_ret="$(fasd -e 'printf %s' "$@")"
[ -z "$_fasd_ret" ] && return (( "${+_fasd_ret}" )) && return
[ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf %s\n "$_fasd_ret" [ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf %s\n "$_fasd_ret"
fi fi
} }
@ -44,7 +44,7 @@ compctl -U -K _fasd_zsh_cmd_complete -V fasd -x 'C[-1,-*e],s[-]n[1,e]' -c - \
# zsh word mode completion # zsh word mode completion
_fasd_zsh_word_complete() { _fasd_zsh_word_complete() {
[ "$2" ] && local _fasd_cur="$2" [ "$2" ] && local _fasd_cur="$2"
[ -z "$_fasd_cur" ] && local _fasd_cur="${words[CURRENT]}" (( "${+_fasd_cur}" )) && local _fasd_cur="${words[CURRENT]}"
local fnd="${_fasd_cur//,/ }" local fnd="${_fasd_cur//,/ }"
local typ=${1:-e} local typ=${1:-e}
fasd --query $typ "$fnd" 2>> "/dev/null" | \ fasd --query $typ "$fnd" 2>> "/dev/null" | \

View file

@ -12,7 +12,7 @@ local url
url="$(command git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")" url="$(command git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")"
if [[ -z "${url}" ]]; then if (( "${+url}" )); then
print "${0}: submodule not found: ${src}" >&2 print "${0}: submodule not found: ${src}" >&2
return 1 return 1
fi fi