From b3c7fde730df23f6cc227d0d32c2786c2235dde9 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 3 Feb 2020 20:43:36 -0500 Subject: [PATCH] Use short `if` form instead of `&&` See http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Alternate-Forms-For-Complex-Commands --- src/stage2/22_zimfw_print.zsh.erb | 4 +-- src/stage2/29_zimfw_build_init.zsh.erb | 4 +-- src/stage2/30_zmodule.zsh.erb | 6 ++-- src/stage2/50_zimfw_clean_compiled.zsh.erb | 2 +- src/stage2/50_zimfw_clean_dumpfile.zsh.erb | 2 +- src/stage2/50_zimfw_compile.zsh.erb | 2 +- src/stage2/50_zimfw_uninstall.zsh.erb | 2 +- src/stage2/50_zimfw_upgrade.zsh.erb | 4 +-- src/tools/install.zsh.erb | 6 ++-- src/tools/update.zsh.erb | 6 ++-- src/zimfw.zsh.erb | 2 +- zimfw.zsh | 42 ++++++++++------------ 12 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/stage2/22_zimfw_print.zsh.erb b/src/stage2/22_zimfw_print.zsh.erb index ed0e6ad..e331c0b 100644 --- a/src/stage2/22_zimfw_print.zsh.erb +++ b/src/stage2/22_zimfw_print.zsh.erb @@ -1,5 +1,3 @@ _zimfw_print() { - if (( _zprintlevel > 0 )); then - print "${@}" - fi + if (( _zprintlevel > 0 )) print "${@}" } diff --git a/src/stage2/29_zimfw_build_init.zsh.erb b/src/stage2/29_zimfw_build_init.zsh.erb index f4e3c1c..71c1aa2 100644 --- a/src/stage2/29_zimfw_build_init.zsh.erb +++ b/src/stage2/29_zimfw_build_init.zsh.erb @@ -6,8 +6,8 @@ _zimfw_build_init() { fi _zimfw_mv =( print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" - (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:A}' ${fpath})' - (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} + if (( ${#_zfpaths} )) print -R 'fpath=('${_zfpaths:A}' ${fpath})' + if (( ${#_zfunctions} )) print -R 'autoload -Uz '${_zfunctions} print -Rn ${(F):-source ${^_zscripts:A}} ) ${ztarget} } diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index ecfa1c2..aec00c5 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -73,7 +73,7 @@ Startup options: -f|--fpath) shift zarg=${1} - [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + if [[ ${zarg} != /* ]] zarg=${zdir}/${zarg} zfpaths+=(${zarg}) ;; -a|--autoload) @@ -83,7 +83,7 @@ Startup options: -s|--source) shift zarg=${1} - [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + if [[ ${zarg} != /* ]] zarg=${zdir}/${zarg} zscripts+=(${zarg}) ;; -d|--disabled) zdisabled=1 ;; @@ -108,7 +108,7 @@ Startup options: _zfailed=1 return 1 fi - (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) + if (( ! ${#zfpaths} )) zfpaths+=(${zdir}/functions(NF)) if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit # prompt_*_setup functions are autoloaded by promptinit diff --git a/src/stage2/50_zimfw_clean_compiled.zsh.erb b/src/stage2/50_zimfw_clean_compiled.zsh.erb index d334771..a9e9021 100644 --- a/src/stage2/50_zimfw_clean_compiled.zsh.erb +++ b/src/stage2/50_zimfw_clean_compiled.zsh.erb @@ -1,6 +1,6 @@ _zimfw_clean_compiled() { local zopt - (( _zprintlevel > 0 )) && zopt='-v' + if (( _zprintlevel > 0 )) zopt='-v' command rm -f ${zopt} ${ZIM_HOME}/**/*.zwc(|.old) || return 1 command rm -f ${zopt} <%= home %>/<%= startup_files_glob %>.zwc(|.old)(N) || return 1 _zimfw_print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' diff --git a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb index 5597a4a..9027971 100644 --- a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb +++ b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb @@ -1,7 +1,7 @@ _zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump - (( _zprintlevel > 0 )) && zopt='-v' + if (( _zprintlevel > 0 )) zopt='-v' command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) || return 1 _zimfw_print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' } diff --git a/src/stage2/50_zimfw_compile.zsh.erb b/src/stage2/50_zimfw_compile.zsh.erb index eb370bf..952f8ef 100644 --- a/src/stage2/50_zimfw_compile.zsh.erb +++ b/src/stage2/50_zimfw_compile.zsh.erb @@ -1,5 +1,5 @@ _zimfw_compile() { local zopt - (( _zprintlevel <= 0 )) && zopt='-q' + if (( _zprintlevel <= 0 )) zopt='-q' source ${ZIM_HOME}/login_init.zsh ${zopt} } diff --git a/src/stage2/50_zimfw_uninstall.zsh.erb b/src/stage2/50_zimfw_uninstall.zsh.erb index d0362c5..fcbe202 100644 --- a/src/stage2/50_zimfw_uninstall.zsh.erb +++ b/src/stage2/50_zimfw_uninstall.zsh.erb @@ -1,6 +1,6 @@ _zimfw_uninstall() { local zopt zdir zmodule - (( _zprintlevel > 0 )) && zopt='-v' + if (( _zprintlevel > 0 )) zopt='-v' for zdir in ${ZIM_HOME}/modules/*(N/); do zmodule=${zdir:t} # If _zmodules and _zdisableds do not contain the zmodule diff --git a/src/stage2/50_zimfw_upgrade.zsh.erb b/src/stage2/50_zimfw_upgrade.zsh.erb index 21d0205..d6bbb24 100644 --- a/src/stage2/50_zimfw_upgrade.zsh.erb +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -7,9 +7,9 @@ _zimfw_upgrade() { command curl -fsSL ${zurl} | command gunzip > ${ztarget}.new || return 1 else local zopt - (( _zprintlevel <= 1 )) && zopt='-q' + if (( _zprintlevel <= 1 )) zopt='-q' if ! command wget -nv ${zopt} -O - ${zurl} | command gunzip > ${ztarget}.new; then - (( _zprintlevel <= 1 )) && print -u2 -PR "%F{red}<%= error %>Error downloading %B${zurl}%b. Use %B-v%b option to see details.%f" + if (( _zprintlevel <= 1 )) print -u2 -PR "%F{red}<%= error %>Error downloading %B${zurl}%b. Use %B-v%b option to see details.%f" return 1 fi fi diff --git a/src/tools/install.zsh.erb b/src/tools/install.zsh.erb index c04956f..34c4bea 100644 --- a/src/tools/install.zsh.erb +++ b/src/tools/install.zsh.erb @@ -9,11 +9,9 @@ if [[ -e ${DIR} ]]; then # Already exists return 0 fi -(( PRINTLEVEL > 0 )) && print -Rn ${CLEAR_LINE}"Installing ${MODULE}<%= ellipsis %>" +if (( PRINTLEVEL > 0 )) print -Rn ${CLEAR_LINE}"Installing ${MODULE}<%= ellipsis %>" if ERR=$(command git clone -b ${REV} -q --recursive ${URL} ${DIR} 2>&1); then - if (( PRINTLEVEL > 0 )); then - print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Installed" - fi + if (( PRINTLEVEL > 0 )) print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Installed" else print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git clone%f"$'\n'${(F):- ${(f)^ERR}} return 1 diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index 5027728..19ab2d6 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -6,7 +6,7 @@ readonly TYPE=${4} readonly REV=${5} readonly -i PRINTLEVEL=${6} readonly CLEAR_LINE=$'\E[2K\r' -(( PRINTLEVEL > 0 )) && print -Rn ${CLEAR_LINE}"Updating ${MODULE}<%= ellipsis %>" +if (( PRINTLEVEL > 0 )) print -Rn ${CLEAR_LINE}"Updating ${MODULE}<%= ellipsis %>" if ! builtin cd -q ${DIR} 2>/dev/null; then print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Not installed%f" return 1 @@ -21,7 +21,7 @@ if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then fi if [[ ${TYPE} == tag ]]; then if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then - (( PRINTLEVEL > 0 )) && print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Already up to date" + if (( PRINTLEVEL > 0 )) print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Already up to date" return 0 fi fi @@ -51,7 +51,7 @@ else fi if ERR=$(command git submodule update --init --recursive -q 2>&1); then if (( PRINTLEVEL > 0 )); then - [[ -n ${LOG} ]] && OUT=${OUT}$'\n'${(F):- ${(f)^LOG}} + if [[ -n ${LOG} ]] OUT=${OUT}$'\n'${(F):- ${(f)^LOG}} print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b ${OUT}" fi else diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index b27dba6..d81114d 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -6,7 +6,7 @@ class Zim @home = "${ZDOTDIR:-${HOME}}" @min_zsh_version = "5.2" @startup_files_glob = ".z(shenv|profile|shrc|login|logout)" - @version = "1.1.1" + @version = "1.2.0-SNAPSHOT" @ellipsis = " ..." @okay = "%F{green})%f " @error = "x " diff --git a/zimfw.zsh b/zimfw.zsh index 04345f2..9dab1ed 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -33,9 +33,7 @@ fi : ${ZIM_HOME=${0:A:h}} _zimfw_print() { - if (( _zprintlevel > 0 )); then - print "${@}" - fi + if (( _zprintlevel > 0 )) print "${@}" } _zimfw_mv() { @@ -58,8 +56,8 @@ _zimfw_build_init() { fi _zimfw_mv =( print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" - (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:A}' ${fpath})' - (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} + if (( ${#_zfpaths} )) print -R 'fpath=('${_zfpaths:A}' ${fpath})' + if (( ${#_zfunctions} )) print -R 'autoload -Uz '${_zfunctions} print -Rn ${(F):-source ${^_zscripts:A}} ) ${ztarget} } @@ -175,7 +173,7 @@ Startup options: -f|--fpath) shift zarg=${1} - [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + if [[ ${zarg} != /* ]] zarg=${zdir}/${zarg} zfpaths+=(${zarg}) ;; -a|--autoload) @@ -185,7 +183,7 @@ Startup options: -s|--source) shift zarg=${1} - [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + if [[ ${zarg} != /* ]] zarg=${zdir}/${zarg} zscripts+=(${zarg}) ;; -d|--disabled) zdisabled=1 ;; @@ -210,7 +208,7 @@ Startup options: _zfailed=1 return 1 fi - (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) + if (( ! ${#zfpaths} )) zfpaths+=(${zdir}/functions(NF)) if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit # prompt_*_setup functions are autoloaded by promptinit @@ -262,7 +260,7 @@ _zimfw_version_check() { _zimfw_clean_compiled() { local zopt - (( _zprintlevel > 0 )) && zopt='-v' + if (( _zprintlevel > 0 )) zopt='-v' command rm -f ${zopt} ${ZIM_HOME}/**/*.zwc(|.old) || return 1 command rm -f ${zopt} ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout).zwc(|.old)(N) || return 1 _zimfw_print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' @@ -271,19 +269,19 @@ _zimfw_clean_compiled() { _zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump - (( _zprintlevel > 0 )) && zopt='-v' + if (( _zprintlevel > 0 )) zopt='-v' command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) || return 1 _zimfw_print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' } _zimfw_compile() { local zopt - (( _zprintlevel <= 0 )) && zopt='-q' + if (( _zprintlevel <= 0 )) zopt='-q' source ${ZIM_HOME}/login_init.zsh ${zopt} } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (previous commit is 6129062)' + print -R 'zimfw version: '${_zversion}' (previous commit is 13fb1ea)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -291,7 +289,7 @@ _zimfw_info() { _zimfw_uninstall() { local zopt zdir zmodule - (( _zprintlevel > 0 )) && zopt='-v' + if (( _zprintlevel > 0 )) zopt='-v' for zdir in ${ZIM_HOME}/modules/*(N/); do zmodule=${zdir:t} # If _zmodules and _zdisableds do not contain the zmodule @@ -311,9 +309,9 @@ _zimfw_upgrade() { command curl -fsSL ${zurl} | command gunzip > ${ztarget}.new || return 1 else local zopt - (( _zprintlevel <= 1 )) && zopt='-q' + if (( _zprintlevel <= 1 )) zopt='-q' if ! command wget -nv ${zopt} -O - ${zurl} | command gunzip > ${ztarget}.new; then - (( _zprintlevel <= 1 )) && print -u2 -PR "%F{red}x Error downloading %B${zurl}%b. Use %B-v%b option to see details.%f" + if (( _zprintlevel <= 1 )) print -u2 -PR "%F{red}x Error downloading %B${zurl}%b. Use %B-v%b option to see details.%f" return 1 fi fi @@ -327,7 +325,7 @@ _zimfw_upgrade() { } zimfw() { - local -r _zversion='1.1.1' + local -r _zversion='1.2.0-SNAPSHOT' local -r zusage="Usage: %B${0}%b [%B-q%b|%B-v%b] Actions: @@ -382,11 +380,9 @@ if [[ -e \${DIR} ]]; then # Already exists return 0 fi -(( PRINTLEVEL > 0 )) && print -Rn \${CLEAR_LINE}\"Installing \${MODULE} ...\" +if (( PRINTLEVEL > 0 )) print -Rn \${CLEAR_LINE}\"Installing \${MODULE} ...\" if ERR=\$(command git clone -b \${REV} -q --recursive \${URL} \${DIR} 2>&1); then - if (( PRINTLEVEL > 0 )); then - print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Installed\" - fi + if (( PRINTLEVEL > 0 )) print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Installed\" else print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git clone%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 @@ -402,7 +398,7 @@ readonly TYPE=\${4} readonly REV=\${5} readonly -i PRINTLEVEL=\${6} readonly CLEAR_LINE=$'\E[2K\r' -(( PRINTLEVEL > 0 )) && print -Rn \${CLEAR_LINE}\"Updating \${MODULE} ...\" +if (( PRINTLEVEL > 0 )) print -Rn \${CLEAR_LINE}\"Updating \${MODULE} ...\" if ! builtin cd -q \${DIR} 2>/dev/null; then print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Not installed%f\" return 1 @@ -417,7 +413,7 @@ if [[ \${URL} != \$(command git config --get remote.origin.url) ]]; then fi if [[ \${TYPE} == tag ]]; then if [[ \${REV} == \$(command git describe --tags --exact-match 2>/dev/null) ]]; then - (( PRINTLEVEL > 0 )) && print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Already up to date\" + if (( PRINTLEVEL > 0 )) print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Already up to date\" return 0 fi fi @@ -447,7 +443,7 @@ else fi if ERR=\$(command git submodule update --init --recursive -q 2>&1); then if (( PRINTLEVEL > 0 )); then - [[ -n \${LOG} ]] && OUT=\${OUT}$'\n'\${(F):- \${(f)^LOG}} + if [[ -n \${LOG} ]] OUT=\${OUT}$'\n'\${(F):- \${(f)^LOG}} print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b \${OUT}\" fi else