From ee99fe8a36334175006e2fb8d96fb64be04174ec Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 11 Jan 2020 16:23:11 -0500 Subject: [PATCH] Add `-v` (verbose) option so the normal output is focused on the given action, and output for additional steps perfomed after the given action is only shown in verbose mode. Also, the output of wget is only shown in verbose mode. This is because wget always shows some output (to stderr) even when there are no errors. See https://serverfault.com/q/70889/302338 This should give a friendlier output. See #360 --- src/stage2/22_zimfw_print.zsh.erb | 2 +- src/stage2/30_zmodule.zsh.erb | 2 +- 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 | 4 +- src/stage2/50_zimfw_uninstall.zsh.erb | 2 +- src/stage2/50_zimfw_upgrade.zsh.erb | 7 ++- src/stage2/80_zimfw.zsh.erb | 27 ++++++--- src/tools/install.zsh.erb | 6 +- src/tools/update.zsh.erb | 8 +-- src/zimfw.zsh.erb | 2 +- zimfw.zsh | 64 ++++++++++++++-------- 12 files changed, 82 insertions(+), 46 deletions(-) diff --git a/src/stage2/22_zimfw_print.zsh.erb b/src/stage2/22_zimfw_print.zsh.erb index 7cb43ca..ed0e6ad 100644 --- a/src/stage2/22_zimfw_print.zsh.erb +++ b/src/stage2/22_zimfw_print.zsh.erb @@ -1,5 +1,5 @@ _zimfw_print() { - if (( ! _zquiet )); then + if (( _zprintlevel > 0 )); then print "${@}" fi } diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 9099c88..429cca0 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -98,7 +98,7 @@ Startup options: done if (( _zprepare_xargs )); then if (( ! zfrozen )); then - _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' + _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zprintlevel}$'\0' fi else if (( zdisabled )); then diff --git a/src/stage2/50_zimfw_clean_compiled.zsh.erb b/src/stage2/50_zimfw_clean_compiled.zsh.erb index 3108796..6082665 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 - (( ! _zquiet )) && zopt='-v' + (( _zprintlevel > 0 )) && zopt='-v' command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || 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 c6b307b..5597a4a 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 - (( ! _zquiet )) && zopt='-v' + (( _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 3d77b5d..eb370bf 100644 --- a/src/stage2/50_zimfw_compile.zsh.erb +++ b/src/stage2/50_zimfw_compile.zsh.erb @@ -1,3 +1,5 @@ _zimfw_compile() { - source ${ZIM_HOME}/login_init.zsh "${@}" + local zopt + (( _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 4c4aaf7..d0362c5 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 - (( ! _zquiet )) && zopt='-v' + (( _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 c352d68..6f32a2f 100644 --- a/src/stage2/50_zimfw_upgrade.zsh.erb +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -3,7 +3,12 @@ _zimfw_upgrade() { local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/master/zimfw.zsh { if (( ${+commands[wget]} )); then - command wget -nv -O ${ztarget}.new ${zurl} || return 1 + local zopt + (( _zprintlevel <= 1 )) && zopt='-q' + if ! command wget -nv ${zopt} -O ${ztarget}.new ${zurl}; then + (( _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 else command curl -fsSL -o ${ztarget}.new ${zurl} || return 1 fi diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 279b3c4..a5bfc89 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -1,6 +1,6 @@ zimfw() { local -r zusage=" -Usage: %B${0}%b [%B-q%b] +Usage: %B${0}%b [%B-q%b|%B-v%b] Actions: %Bbuild%b Build init.zsh and login_init.zsh @@ -16,16 +16,18 @@ Actions: Options: %B-q%b Quiet, only outputs errors + %B-v%b Verbose " local ztool _zmodules_xargs local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts - local -i _zquiet=0 + local -i _zprintlevel=1 if (( # > 2 )); then print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} return 1 elif (( # > 1 )); then case ${2} in - -q) _zquiet=1 ;; + -q) _zprintlevel=0 ;; + -v) _zprintlevel=2 ;; *) print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} return 1 @@ -43,21 +45,30 @@ Options: esac case ${1} in - build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + build) + _zimfw_source_zimrc && _zimfw_build || return 1 + (( _zprintlevel-- )) + _zimfw_compile + ;; init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_clean_compiled && _zimfw_clean_dumpfile ;; clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; - compile) _zimfw_build_login_init && _zimfw_compile ${2} ;; + compile) _zimfw_build_login_init && _zimfw_compile ;; info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ - _zimfw_print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect." && \ - _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} + _zimfw_print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect." || return 1 + (( _zprintlevel-- )) + _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ;; uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;; - upgrade) _zimfw_upgrade && _zimfw_build_login_init && _zimfw_compile ${2} ;; + upgrade) + _zimfw_upgrade || return 1 + (( _zprintlevel-- )) + _zimfw_build_login_init && _zimfw_compile + ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1 diff --git a/src/tools/install.zsh.erb b/src/tools/install.zsh.erb index bd7251d..c04956f 100644 --- a/src/tools/install.zsh.erb +++ b/src/tools/install.zsh.erb @@ -3,15 +3,15 @@ readonly MODULE=${1} readonly DIR=${2} readonly URL=${3} readonly REV=${5} -readonly -i QUIET=${6} +readonly -i PRINTLEVEL=${6} readonly CLEAR_LINE=$'\E[2K\r' if [[ -e ${DIR} ]]; then # Already exists return 0 fi -(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Installing ${MODULE}<%= ellipsis %>" +(( PRINTLEVEL > 0 )) && print -Rn ${CLEAR_LINE}"Installing ${MODULE}<%= ellipsis %>" if ERR=$(command git clone -b ${REV} -q --recursive ${URL} ${DIR} 2>&1); then - if (( ! QUIET )); then + if (( PRINTLEVEL > 0 )); then print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Installed" fi else diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index 287b478..5027728 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -4,9 +4,9 @@ readonly DIR=${2} readonly URL=${3} readonly TYPE=${4} readonly REV=${5} -readonly -i QUIET=${6} +readonly -i PRINTLEVEL=${6} readonly CLEAR_LINE=$'\E[2K\r' -(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Updating ${MODULE}<%= ellipsis %>" +(( 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 - (( ! QUIET )) && print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Already up to date" + (( PRINTLEVEL > 0 )) && print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Already up to date" return 0 fi fi @@ -50,7 +50,7 @@ else OUT="Updating to ${TYPE} ${REV}" fi if ERR=$(command git submodule update --init --recursive -q 2>&1); then - if (( ! QUIET )); then + if (( PRINTLEVEL > 0 )); then [[ -n ${LOG} ]] && OUT=${OUT}$'\n'${(F):- ${(f)^LOG}} print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b ${OUT}" fi diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index 49426b6..7ca5604 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.0.1" + @version = "1.1.0-SNAPSHOT" @ellipsis = " ..." @okay = "%F{green})%f " @error = "x " diff --git a/zimfw.zsh b/zimfw.zsh index aae5cdf..4714309 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -33,7 +33,7 @@ fi : ${ZIM_HOME=${0:A:h}} _zimfw_print() { - if (( ! _zquiet )); then + if (( _zprintlevel > 0 )); then print "${@}" fi } @@ -200,7 +200,7 @@ Startup options: done if (( _zprepare_xargs )); then if (( ! zfrozen )); then - _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' + _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zprintlevel}$'\0' fi else if (( zdisabled )); then @@ -239,7 +239,7 @@ _zimfw_source_zimrc() { _zimfw_clean_compiled() { local zopt - (( ! _zquiet )) && zopt='-v' + (( _zprintlevel > 0 )) && zopt='-v' command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || 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.' @@ -248,17 +248,19 @@ _zimfw_clean_compiled() { _zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump - (( ! _zquiet )) && zopt='-v' + (( _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() { - source ${ZIM_HOME}/login_init.zsh "${@}" + local zopt + (( _zprintlevel <= 0 )) && zopt='-q' + source ${ZIM_HOME}/login_init.zsh ${zopt} } _zimfw_info() { - print 'Zim version: 1.0.1 (previous commit is 28e4345)' + print 'Zim version: 1.1.0-SNAPSHOT (previous commit is b9bca2d)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -266,7 +268,7 @@ _zimfw_info() { _zimfw_uninstall() { local zopt zdir zmodule - (( ! _zquiet )) && zopt='-v' + (( _zprintlevel > 0 )) && zopt='-v' for zdir in ${ZIM_HOME}/modules/*(N/); do zmodule=${zdir:t} # If _zmodules and _zdisableds do not contain the zmodule @@ -282,7 +284,12 @@ _zimfw_upgrade() { local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/master/zimfw.zsh { if (( ${+commands[wget]} )); then - command wget -nv -O ${ztarget}.new ${zurl} || return 1 + local zopt + (( _zprintlevel <= 1 )) && zopt='-q' + if ! command wget -nv ${zopt} -O ${ztarget}.new ${zurl}; then + (( _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 else command curl -fsSL -o ${ztarget}.new ${zurl} || return 1 fi @@ -294,7 +301,7 @@ _zimfw_upgrade() { zimfw() { local -r zusage=" -Usage: %B${0}%b [%B-q%b] +Usage: %B${0}%b [%B-q%b|%B-v%b] Actions: %Bbuild%b Build init.zsh and login_init.zsh @@ -310,16 +317,18 @@ Actions: Options: %B-q%b Quiet, only outputs errors + %B-v%b Verbose " local ztool _zmodules_xargs local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts - local -i _zquiet=0 + local -i _zprintlevel=1 if (( # > 2 )); then print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} return 1 elif (( # > 1 )); then case ${2} in - -q) _zquiet=1 ;; + -q) _zprintlevel=0 ;; + -v) _zprintlevel=2 ;; *) print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} return 1 @@ -334,15 +343,15 @@ readonly MODULE=\${1} readonly DIR=\${2} readonly URL=\${3} readonly REV=\${5} -readonly -i QUIET=\${6} +readonly -i PRINTLEVEL=\${6} readonly CLEAR_LINE=$'\E[2K\r' if [[ -e \${DIR} ]]; then # Already exists return 0 fi -(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Installing \${MODULE} ...\" +(( PRINTLEVEL > 0 )) && print -Rn \${CLEAR_LINE}\"Installing \${MODULE} ...\" if ERR=\$(command git clone -b \${REV} -q --recursive \${URL} \${DIR} 2>&1); then - if (( ! QUIET )); then + if (( PRINTLEVEL > 0 )); then print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Installed\" fi else @@ -358,9 +367,9 @@ readonly DIR=\${2} readonly URL=\${3} readonly TYPE=\${4} readonly REV=\${5} -readonly -i QUIET=\${6} +readonly -i PRINTLEVEL=\${6} readonly CLEAR_LINE=$'\E[2K\r' -(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Updating \${MODULE} ...\" +(( 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 @@ -375,7 +384,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 - (( ! QUIET )) && print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Already up to date\" + (( PRINTLEVEL > 0 )) && print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Already up to date\" return 0 fi fi @@ -404,7 +413,7 @@ else OUT=\"Updating to \${TYPE} \${REV}\" fi if ERR=\$(command git submodule update --init --recursive -q 2>&1); then - if (( ! QUIET )); then + if (( PRINTLEVEL > 0 )); then [[ -n \${LOG} ]] && OUT=\${OUT}$'\n'\${(F):- \${(f)^LOG}} print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b \${OUT}\" fi @@ -417,21 +426,30 @@ fi esac case ${1} in - build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + build) + _zimfw_source_zimrc && _zimfw_build || return 1 + (( _zprintlevel-- )) + _zimfw_compile + ;; init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_clean_compiled && _zimfw_clean_dumpfile ;; clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; - compile) _zimfw_build_login_init && _zimfw_compile ${2} ;; + compile) _zimfw_build_login_init && _zimfw_compile ;; info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ - _zimfw_print -PR "Done with ${1}. Restart your terminal for any changes to take effect." && \ - _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} + _zimfw_print -PR "Done with ${1}. Restart your terminal for any changes to take effect." || return 1 + (( _zprintlevel-- )) + _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ;; uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;; - upgrade) _zimfw_upgrade && _zimfw_build_login_init && _zimfw_compile ${2} ;; + upgrade) + _zimfw_upgrade || return 1 + (( _zprintlevel-- )) + _zimfw_build_login_init && _zimfw_compile + ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1