From 393bd00114ba6618b8420cc4e2b5aae900ca66d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=84=B3ichiel=20=E2=84=9Boos?= Date: Wed, 10 May 2017 21:30:47 +0200 Subject: [PATCH] Use zsh style tests for empty vars --- modules/environment/init.zsh | 2 +- modules/fasd/functions/fasd | 36 ++++++++++++------------ modules/fasd/init.zsh | 4 +-- modules/git/functions/git-submodule-move | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/environment/init.zsh b/modules/environment/init.zsh index 36810ee..142170b 100644 --- a/modules/environment/init.zsh +++ b/modules/environment/init.zsh @@ -39,7 +39,7 @@ unsetopt HUP unsetopt CHECK_JOBS # Set less or more as the default pager. -if [[ -z ${PAGER} ]]; then +if (( ${+PAGER} )); then if (( ${+commands[less]} )); then export PAGER=less else diff --git a/modules/fasd/functions/fasd b/modules/fasd/functions/fasd index fc16ee7..b19a6f8 100644 --- a/modules/fasd/functions/fasd +++ b/modules/fasd/functions/fasd @@ -41,20 +41,20 @@ case $1 in fi # set default options - [ -z "$_FASD_DATA" ] && _FASD_DATA="$HOME/.fasd" - [ -z "$_FASD_BLACKLIST" ] && _FASD_BLACKLIST="--help" - [ -z "$_FASD_SHIFT" ] && _FASD_SHIFT="sudo busybox" - [ -z "$_FASD_IGNORE" ] && _FASD_IGNORE="fasd ls echo" - [ -z "$_FASD_SINK" ] && _FASD_SINK=/dev/null - [ -z "$_FASD_TRACK_PWD" ] && _FASD_TRACK_PWD=1 - [ -z "$_FASD_MAX" ] && _FASD_MAX=2000 - [ -z "$_FASD_BACKENDS" ] && _FASD_BACKENDS=native - [ -z "$_FASD_FUZZY" ] && _FASD_FUZZY=2 - [ -z "$_FASD_VIMINFO" ] && _FASD_VIMINFO="$HOME/.viminfo" - [ -z "$_FASD_RECENTLY_USED_XBEL" ] && \ + (( "${+_FASD_DATA}" )) && _FASD_DATA="$HOME/.fasd" + (( "${+_FASD_BLACKLIST}" )) && _FASD_BLACKLIST="--help" + (( "${+_FASD_SHIFT}" )) && _FASD_SHIFT="sudo busybox" + (( "${+_FASD_IGNORE}" )) && _FASD_IGNORE="fasd ls echo" + (( "${+_FASD_SINK}" )) && _FASD_SINK=/dev/null + (( "${+_FASD_TRACK_PWD}" )) && _FASD_TRACK_PWD=1 + (( "${+_FASD_MAX}" )) && _FASD_MAX=2000 + (( "${+_FASD_BACKENDS}" )) && _FASD_BACKENDS=native + (( "${+_FASD_FUZZY}" )) && _FASD_FUZZY=2 + (( "${+_FASD_VIMINFO}" )) && _FASD_VIMINFO="$HOME/.viminfo" + (( "${+_FASD_RECENTLY_USED_XBEL}" )) && \ _FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel" - if [ -z "$_FASD_AWK" ]; then + if (( "${+_FASD_AWK}" )); then # awk preferences local awk; for awk in mawk gawk original-awk nawk awk; do $awk "" && _FASD_AWK=$awk && break @@ -125,7 +125,7 @@ case $1 in # add current pwd if the option is set [ "$_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 local tempfile @@ -312,12 +312,12 @@ $(fasd --backend $each)" while [ "$1" ]; do case $1 in --complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;; --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;; -*) local o="${1#-}"; while [ "$o" ]; do case $o in s*) local show=1;; l*) local lst=1;; - i*) [ -z "$comp" ] && local interactive=1 show=1;; + i*) (( "${+comp}" )) && local interactive=1 show=1;; r*) local mode=rank;; t*) local mode=recent;; e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e" @@ -343,7 +343,7 @@ $(fasd --backend $each)" f*) local typ=f;; R*) local r=r;; [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 ...] options: -s list paths with scores @@ -376,7 +376,7 @@ fasd [-A|-D] [paths ...] fi;; 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# }" local res @@ -407,7 +407,7 @@ fasd [-A|-D] [paths ...] fi if [ "$res" ]; then fasd --add "$res" - [ -z "$exec" ] && exec='printf %s\n' + (( "${+exec}" )) && exec='printf %s\n' $exec "$res" fi ;; diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh index cc05f62..8fdffa4 100644 --- a/modules/fasd/init.zsh +++ b/modules/fasd/init.zsh @@ -6,7 +6,7 @@ fasd_cd() { fasd "$@" else 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" 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 _fasd_zsh_word_complete() { [ "$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 typ=${1:-e} fasd --query $typ "$fnd" 2>> "/dev/null" | \ diff --git a/modules/git/functions/git-submodule-move b/modules/git/functions/git-submodule-move index 0596785..8eadc1d 100644 --- a/modules/git/functions/git-submodule-move +++ b/modules/git/functions/git-submodule-move @@ -12,7 +12,7 @@ local 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 return 1 fi