From 741bb78a04c978e223b4df845ed6ae9291e54eec Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 7 May 2022 16:31:08 -0500 Subject: [PATCH] Add `--on-pull` option to `zmodule` Fixes #456 --- CHANGELOG.md | 5 +- README.md | 4 ++ src/stage2/30_zmodule.zsh.erb | 13 ++-- src/stage2/50_zimfw_install_update.zsh.erb | 2 +- src/stage2/69_zimfw_run_list.zsh.erb | 5 +- src/stage2/70_zimfw_run_tool.zsh.erb | 4 +- src/stage2/80_zimfw.zsh.erb | 6 +- src/tools/degit.zsh.erb | 26 +++++-- src/tools/git.zsh.erb | 22 ++++-- src/zimfw.zsh.erb | 2 +- zimfw.zsh | 82 +++++++++++++++------- 11 files changed, 119 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 832fb2e..b091c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -_No unreleased changes._ +### Added + +- `--on-pull` option to `zmodule`, which allows setting a command that is always triggered + after the module is installed or updated. ## [1.8.0] - 2022-01-25 diff --git a/README.md b/README.md index 57907b3..9638ede 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,8 @@ Below are some usage examples: `zmodule sindresorhus/pure --source async.zsh --source pure.zsh` * A module with a custom initialization command: `zmodule skywind3000/z.lua --cmd 'eval "$(lua {}/z.lua --init zsh enhanced once)"'` + * A module with an on-pull command. It can be used to create a cached initialization script: + `zmodule skywind3000/z.lua --on-pull 'lua z.lua --init zsh enhanced once >! init.zsh'` * A module with a big git repository: `zmodule romkatv/powerlevel10k --use degit`
@@ -224,6 +226,8 @@ Repository options: changes are lost on updates. Git submodules are not supported. --no-submodules Don't install or update git submodules. -z|--frozen Don't install or update the module. + --on-pull <command> Execute command after installing or updating the module. The com- + mand is executed in the module root directory. Initialization options: -f|--fpath <path> Add specified path to fpath. The path is relative to the module diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index e934c65..da71c2a 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -24,7 +24,8 @@ Repository options: changes are lost on updates. Git submodules are not supported. %B--no-submodules%b Don't install or update git submodules. %B-z%b|%B--frozen%b Don't install or update the module. - + %B--on-pull%b Execute command after installing or updating the module. The com- + mand is executed in the module root directory. Initialization options: %B-f%b|%B--fpath%b Add specified path to fpath. The path is relative to the module root directory. Default: %Bfunctions%b, if the subdirectory exists. @@ -53,7 +54,7 @@ Initialization options: fi local zurl=${1} zmodule=${1:t} ztool zdir ztype zrev zarg local -i zsubmodules=1 zfrozen=0 zdisabled=0 - local -a zfpaths zfunctions zcmds + local -a zonpulls zfpaths zfunctions zcmds zstyle -s ':zim:zmodule' use 'ztool' || ztool=git if [[ ${zurl} =~ ^[^:/]+: ]]; then zmodule=${zmodule%.git} @@ -83,7 +84,7 @@ Initialization options: fi while (( # > 0 )); do case ${1} in - -b|--branch|-t|--tag|-u|--use|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd) + -b|--branch|-t|--tag|-u|--use|--on-pull|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd) if (( # < 2 )); then print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option %B${1}%b%f" '' ${zusage} _zfailed=1 @@ -113,6 +114,10 @@ Initialization options: ;; --no-submodules) zsubmodules=0 ;; -z|--frozen) zfrozen=1 ;; + --on-pull) + shift + zonpulls+=(${1}) + ;; -f|--fpath) shift zarg=${1} @@ -143,7 +148,7 @@ Initialization options: shift done if (( _zflags & 1 )); then - _zmodules_zargs+=("${ztool}" "${_zargs_action}" "${zmodule}" "${zdir}" "${zurl}" "${ztype}" "${zrev}" "${zsubmodules}" "${zfrozen}" "${zdisabled}") + _zmodules_zargs+=("${ztool}" "${_zargs_action}" "${zmodule}" "${zdir}" "${zurl}" "${ztype}" "${zrev}" "${zsubmodules}" "${(j:; :)zonpulls}" "${zfrozen}" "${zdisabled}") fi if (( _zflags & 2 )); then if (( zdisabled )); then diff --git a/src/stage2/50_zimfw_install_update.zsh.erb b/src/stage2/50_zimfw_install_update.zsh.erb index b13b3c4..bb21391 100644 --- a/src/stage2/50_zimfw_install_update.zsh.erb +++ b/src/stage2/50_zimfw_install_update.zsh.erb @@ -1,3 +1,3 @@ _zimfw_install_update() { - _zimfw_source_zimrc 1 ${1} && zargs -n 10 -P 0 -- "${_zmodules_zargs[@]}" -- _zimfw_run_tool + _zimfw_source_zimrc 1 ${1} && zargs -n 11 -P 0 -- "${_zmodules_zargs[@]}" -- _zimfw_run_tool } diff --git a/src/stage2/69_zimfw_run_list.zsh.erb b/src/stage2/69_zimfw_run_list.zsh.erb index c4d8c93..bb3006d 100644 --- a/src/stage2/69_zimfw_run_list.zsh.erb +++ b/src/stage2/69_zimfw_run_list.zsh.erb @@ -1,6 +1,6 @@ _zimfw_run_list() { - local -r ztool=${1} zmodule=${3} zdir=${4} zurl=${5} ztype=${6} zrev=${7} - local -ri zsubmodules=${8} zfrozen=${9} zdisabled=${10} + local -r ztool=${1} zmodule=${3} zdir=${4} zurl=${5} ztype=${6} zrev=${7} zonpull=${9} + local -ri zsubmodules=${8} zfrozen=${10} zdisabled=${11} print -PnR "%B${zmodule}:%b ${zdir}" if [[ -z ${zurl} ]] print -Pn ' (external)' if (( ${zfrozen} )) print -Pn ' (frozen)' @@ -17,6 +17,7 @@ _zimfw_run_list() { print -nR ", using ${ztool}" if (( ! zsubmodules )) print -nR ', no git submodules' print + if [[ -n ${zonpull} ]] print -R " On-pull: ${zonpull}" fi # Match and remove the current module prefix from _zfpaths, _zfunctions and _zcmds local -r zpre=${zmodule}$'\0' diff --git a/src/stage2/70_zimfw_run_tool.zsh.erb b/src/stage2/70_zimfw_run_tool.zsh.erb index fa31cc7..d518287 100644 --- a/src/stage2/70_zimfw_run_tool.zsh.erb +++ b/src/stage2/70_zimfw_run_tool.zsh.erb @@ -4,7 +4,7 @@ _zimfw_run_tool() { if (( _zprintlevel > 1 )) print -u2 -PR <%= clear_line %>"<%= okay %>%B${zmodule}:%b Skipping external module" return 0 fi - local -ri zfrozen=${9} + local -ri zfrozen=${10} if (( zfrozen )); then if (( _zprintlevel > 1 )) print -u2 -PR <%= clear_line %>"<%= okay %>%B${zmodule}:%b Skipping frozen module" return 0 @@ -37,5 +37,5 @@ _zimfw_run_tool() { return 1 ;; esac - zsh -c ${zcmd} ${ztool} ${_zprintlevel} "${@[2,8]}" + zsh -c ${zcmd} ${ztool} ${_zprintlevel} "${@[2,9]}" } diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index f44bbac..219cbe5 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -16,10 +16,10 @@ Actions: Use %B-v%b to also see the modules details. %Binit%b Same as %Binstall%b, but with output tailored to be used at terminal startup. %Binstall%b Install new modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to - also see their output, and see skipped modules. + also see their output, any on-pull output, and see skipped modules. %Buninstall%b Delete unused modules. Prompts for confirmation. Use %B-q%b for quiet uninstall. %Bupdate%b Update current modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b - to also see their output, and see skipped modules. + to also see their output, any on-pull output, and see skipped modules. %Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output. %Bversion%b Print zimfw version. @@ -61,7 +61,7 @@ Options: help) print -PR ${zusage} ;; info) _zimfw_info ;; list) - _zimfw_source_zimrc 3 && zargs -n 10 -- "${_zmodules_zargs[@]}" -- _zimfw_run_list && \ + _zimfw_source_zimrc 3 && zargs -n 11 -- "${_zmodules_zargs[@]}" -- _zimfw_run_list && \ _zimfw_list_unuseds ' (unused)' ;; init) diff --git a/src/tools/degit.zsh.erb b/src/tools/degit.zsh.erb index e4f03c6..cb58593 100644 --- a/src/tools/degit.zsh.erb +++ b/src/tools/degit.zsh.erb @@ -1,7 +1,7 @@ # This runs in a new shell builtin emulate -L zsh -o EXTENDED_GLOB readonly -i PRINTLEVEL=${1} SUBMODULES=${8} -readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} TEMP=.zdegit_${RANDOM} +readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} ONPULL=${9} TEMP=.zdegit_${RANDOM} readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit print_error() { @@ -12,13 +12,25 @@ print_okay() { if (( PRINTLEVEL > 0 )); then local -r log=${2:+${(F):- ${(f)^2}}} if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then - print -u2 -PlR <%= clear_line %>"%F{yellow}<%= warn %>%B${MODULE}:%b ${(C)1}. Module contains git submodules, which are not supported by Zim's degit and were not ${1}. Use zmodule option %B--no-submodules%b to disable this warning.%f" ${log} + print -u2 -PlR <%= clear_line %>"%F{yellow}<%= warn %>%B${MODULE}:%b ${1}. Module contains git submodules, which are not supported by Zim's degit. Use zmodule option %B--no-submodules%b to disable this warning.%f" ${log} else - print -PlR <%= clear_line %>"<%= okay %>%B${MODULE}:%b ${(C)1}" ${log} + print -PlR <%= clear_line %>"<%= okay %>%B${MODULE}:%b ${1}" ${log} fi fi } +handle() { + if [[ -n ${ONPULL} ]]; then + if ! ERR=$(builtin cd -q ${DIR} 2>&1 && eval ${ONPULL} 2>&1); then + print_error 'Error during on-pull' ${ERR} + return 1 + elif [[ ${PRINTLEVEL} -gt 1 && -n ${ERR} ]]; then + set ${1} ${2:+${2}$'\n'}"On-pull output:"$'\n'${ERR} + fi + fi + print_okay "${@}" +} + download_tarball() { local host repo if [[ ${URL} =~ <%= url_regex %> ]]; then @@ -98,7 +110,7 @@ create_dir() { case ${ACTION} in install) { - create_dir ${DIR} && download_tarball && untar_tarball ${DIR} && print_okay installed + create_dir ${DIR} && download_tarball && untar_tarball ${DIR} && handle Installed } always { # return 1 does not change ${TRY_BLOCK_ERROR}, only changes ${?} (( TRY_BLOCK_ERROR = ? )) @@ -117,8 +129,8 @@ case ${ACTION} in { download_tarball || return 1 if [[ ! -e ${TARBALL_TARGET} ]]; then - if (( PRINTLEVEL > 0 )) print -PR <%= clear_line %>"<%= okay %>%B${MODULE}:%b Already up to date" - return 0 + handle 'Already up to date' + return ${?} fi create_dir ${DIR_NEW} && untar_tarball ${DIR_NEW} || return 1 if (( ${+commands[diff]} )); then @@ -130,7 +142,7 @@ case ${ACTION} in print_error "Error updating ${DIR}" ${ERR} return 1 fi - print_okay updated ${LOG} + handle Updated ${LOG} } always { command rm -f ${TARBALL_TARGET} 2>/dev/null command rm -rf ${DIR_NEW} 2>/dev/null diff --git a/src/tools/git.zsh.erb b/src/tools/git.zsh.erb index 27d8c06..b7fd8ab 100644 --- a/src/tools/git.zsh.erb +++ b/src/tools/git.zsh.erb @@ -1,7 +1,7 @@ # This runs in a new shell builtin emulate -L zsh readonly -i PRINTLEVEL=${1} SUBMODULES=${8} -readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} TYPE=${6:=branch} +readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} TYPE=${6:=branch} ONPULL=${9} REV=${7} print_error() { @@ -12,10 +12,22 @@ print_okay() { if (( PRINTLEVEL > 0 )) print -PlR <%= clear_line %>"<%= okay %>%B${MODULE}:%b ${1}" ${2:+${(F):- ${(f)^2}}} } +handle() { + if [[ -n ${ONPULL} ]]; then + if ! ERR=$(builtin cd -q ${DIR} 2>&1 && eval ${ONPULL} 2>&1); then + print_error 'Error during on-pull' ${ERR} + return 1 + elif [[ ${PRINTLEVEL} -gt 1 && -n ${ERR} ]]; then + set ${1} ${2:+${2}$'\n'}"On-pull output:"$'\n'${ERR} + fi + fi + print_okay "${@}" +} + case ${ACTION} in install) if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then - print_okay Installed + handle Installed else print_error 'Error during git clone' ${ERR} return 1 @@ -38,8 +50,8 @@ case ${ACTION} in fi if [[ ${TYPE} == tag ]]; then if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then - print_okay 'Already up to date' - return 0 + handle 'Already up to date' + return ${?} fi elif [[ -z ${REV} ]]; then # Get HEAD remote branch @@ -80,6 +92,6 @@ case ${ACTION} in return 1 fi fi - print_okay ${OUT} ${LOG} + handle ${OUT} ${LOG} ;; esac diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index a433158..e81296f 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -4,7 +4,7 @@ class Zim :clear_line, :ellipsis, :okay, :warn, :error, :done, :failed def initialize - @version = "1.8.0" + @version = "1.9.0-SNAPSHOT" @home = "${ZDOTDIR:-${HOME}}" @min_zsh_version = "5.2" # Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo diff --git a/zimfw.zsh b/zimfw.zsh index f0fc188..7d85e59 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -110,7 +110,8 @@ Repository options: changes are lost on updates. Git submodules are not supported. %B--no-submodules%b Don't install or update git submodules. %B-z%b|%B--frozen%b Don't install or update the module. - + %B--on-pull%b Execute command after installing or updating the module. The com- + mand is executed in the module root directory. Initialization options: %B-f%b|%B--fpath%b Add specified path to fpath. The path is relative to the module root directory. Default: %Bfunctions%b, if the subdirectory exists. @@ -139,7 +140,7 @@ Initialization options: fi local zurl=${1} zmodule=${1:t} ztool zdir ztype zrev zarg local -i zsubmodules=1 zfrozen=0 zdisabled=0 - local -a zfpaths zfunctions zcmds + local -a zonpulls zfpaths zfunctions zcmds zstyle -s ':zim:zmodule' use 'ztool' || ztool=git if [[ ${zurl} =~ ^[^:/]+: ]]; then zmodule=${zmodule%.git} @@ -169,7 +170,7 @@ Initialization options: fi while (( # > 0 )); do case ${1} in - -b|--branch|-t|--tag|-u|--use|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd) + -b|--branch|-t|--tag|-u|--use|--on-pull|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd) if (( # < 2 )); then print -u2 -PlR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option %B${1}%b%f" '' ${zusage} _zfailed=1 @@ -199,6 +200,10 @@ Initialization options: ;; --no-submodules) zsubmodules=0 ;; -z|--frozen) zfrozen=1 ;; + --on-pull) + shift + zonpulls+=(${1}) + ;; -f|--fpath) shift zarg=${1} @@ -229,7 +234,7 @@ Initialization options: shift done if (( _zflags & 1 )); then - _zmodules_zargs+=("${ztool}" "${_zargs_action}" "${zmodule}" "${zdir}" "${zurl}" "${ztype}" "${zrev}" "${zsubmodules}" "${zfrozen}" "${zdisabled}") + _zmodules_zargs+=("${ztool}" "${_zargs_action}" "${zmodule}" "${zdir}" "${zurl}" "${ztype}" "${zrev}" "${zsubmodules}" "${(j:; :)zonpulls}" "${zfrozen}" "${zdisabled}") fi if (( _zflags & 2 )); then if (( zdisabled )); then @@ -379,14 +384,14 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (built at 2022-01-25 22:16:46 UTC, previous commit is 72fe20c)' + print -R 'zimfw version: '${_zversion}' (built at 2022-05-07 21:29:52 UTC, previous commit is e0fe8ef)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) } _zimfw_install_update() { - _zimfw_source_zimrc 1 ${1} && zargs -n 10 -P 0 -- "${_zmodules_zargs[@]}" -- _zimfw_run_tool + _zimfw_source_zimrc 1 ${1} && zargs -n 11 -P 0 -- "${_zmodules_zargs[@]}" -- _zimfw_run_tool } _zimfw_uninstall() { @@ -427,8 +432,8 @@ _zimfw_upgrade() { } _zimfw_run_list() { - local -r ztool=${1} zmodule=${3} zdir=${4} zurl=${5} ztype=${6} zrev=${7} - local -ri zsubmodules=${8} zfrozen=${9} zdisabled=${10} + local -r ztool=${1} zmodule=${3} zdir=${4} zurl=${5} ztype=${6} zrev=${7} zonpull=${9} + local -ri zsubmodules=${8} zfrozen=${10} zdisabled=${11} print -PnR "%B${zmodule}:%b ${zdir}" if [[ -z ${zurl} ]] print -Pn ' (external)' if (( ${zfrozen} )) print -Pn ' (frozen)' @@ -445,6 +450,7 @@ _zimfw_run_list() { print -nR ", using ${ztool}" if (( ! zsubmodules )) print -nR ', no git submodules' print + if [[ -n ${zonpull} ]] print -R " On-pull: ${zonpull}" fi # Match and remove the current module prefix from _zfpaths, _zfunctions and _zcmds local -r zpre=${zmodule}$'\0' @@ -461,7 +467,7 @@ _zimfw_run_tool() { if (( _zprintlevel > 1 )) print -u2 -PR $'\E[2K\r'"%F{green})%f %B${zmodule}:%b Skipping external module" return 0 fi - local -ri zfrozen=${9} + local -ri zfrozen=${10} if (( zfrozen )); then if (( _zprintlevel > 1 )) print -u2 -PR $'\E[2K\r'"%F{green})%f %B${zmodule}:%b Skipping frozen module" return 0 @@ -491,7 +497,7 @@ _zimfw_run_tool() { degit) zcmd="# This runs in a new shell builtin emulate -L zsh -o EXTENDED_GLOB readonly -i PRINTLEVEL=\${1} SUBMODULES=\${8} -readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} TEMP=.zdegit_\${RANDOM} +readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} ONPULL=\${9} TEMP=.zdegit_\${RANDOM} readonly TARBALL_TARGET=\${DIR}/\${TEMP}_tarball.tar.gz INFO_TARGET=\${DIR}/.zdegit print_error() { @@ -502,13 +508,25 @@ print_okay() { if (( PRINTLEVEL > 0 )); then local -r log=\${2:+\${(F):- \${(f)^2}}} if [[ \${SUBMODULES} -ne 0 && -e \${DIR}/.gitmodules ]]; then - print -u2 -PlR $'\E[2K\r'\"%F{yellow}! %B\${MODULE}:%b \${(C)1}. Module contains git submodules, which are not supported by Zim's degit and were not \${1}. Use zmodule option %B--no-submodules%b to disable this warning.%f\" \${log} + print -u2 -PlR $'\E[2K\r'\"%F{yellow}! %B\${MODULE}:%b \${1}. Module contains git submodules, which are not supported by Zim's degit. Use zmodule option %B--no-submodules%b to disable this warning.%f\" \${log} else - print -PlR $'\E[2K\r'\"%F{green})%f %B\${MODULE}:%b \${(C)1}\" \${log} + print -PlR $'\E[2K\r'\"%F{green})%f %B\${MODULE}:%b \${1}\" \${log} fi fi } +handle() { + if [[ -n \${ONPULL} ]]; then + if ! ERR=\$(builtin cd -q \${DIR} 2>&1 && eval \${ONPULL} 2>&1); then + print_error 'Error during on-pull' \${ERR} + return 1 + elif [[ \${PRINTLEVEL} -gt 1 && -n \${ERR} ]]; then + set \${1} \${2:+\${2}$'\n'}\"On-pull output:\"$'\n'\${ERR} + fi + fi + print_okay \"\${@}\" +} + download_tarball() { local host repo if [[ \${URL} =~ ^([^:@/]+://)?([^@]+@)?([^:/]+)[:/]([^/]+/[^/]+)/?\$ ]]; then @@ -588,7 +606,7 @@ create_dir() { case \${ACTION} in install) { - create_dir \${DIR} && download_tarball && untar_tarball \${DIR} && print_okay installed + create_dir \${DIR} && download_tarball && untar_tarball \${DIR} && handle Installed } always { # return 1 does not change \${TRY_BLOCK_ERROR}, only changes \${?} (( TRY_BLOCK_ERROR = ? )) @@ -607,8 +625,8 @@ case \${ACTION} in { download_tarball || return 1 if [[ ! -e \${TARBALL_TARGET} ]]; then - if (( PRINTLEVEL > 0 )) print -PR $'\E[2K\r'\"%F{green})%f %B\${MODULE}:%b Already up to date\" - return 0 + handle 'Already up to date' + return \${?} fi create_dir \${DIR_NEW} && untar_tarball \${DIR_NEW} || return 1 if (( \${+commands[diff]} )); then @@ -620,7 +638,7 @@ case \${ACTION} in print_error \"Error updating \${DIR}\" \${ERR} return 1 fi - print_okay updated \${LOG} + handle Updated \${LOG} } always { command rm -f \${TARBALL_TARGET} 2>/dev/null command rm -rf \${DIR_NEW} 2>/dev/null @@ -631,7 +649,7 @@ esac git) zcmd="# This runs in a new shell builtin emulate -L zsh readonly -i PRINTLEVEL=\${1} SUBMODULES=\${8} -readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} TYPE=\${6:=branch} +readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} TYPE=\${6:=branch} ONPULL=\${9} REV=\${7} print_error() { @@ -642,10 +660,22 @@ print_okay() { if (( PRINTLEVEL > 0 )) print -PlR $'\E[2K\r'\"%F{green})%f %B\${MODULE}:%b \${1}\" \${2:+\${(F):- \${(f)^2}}} } +handle() { + if [[ -n \${ONPULL} ]]; then + if ! ERR=\$(builtin cd -q \${DIR} 2>&1 && eval \${ONPULL} 2>&1); then + print_error 'Error during on-pull' \${ERR} + return 1 + elif [[ \${PRINTLEVEL} -gt 1 && -n \${ERR} ]]; then + set \${1} \${2:+\${2}$'\n'}\"On-pull output:\"$'\n'\${ERR} + fi + fi + print_okay \"\${@}\" +} + case \${ACTION} in install) if ERR=\$(command git clone \${REV:+-b} \${REV} -q --config core.autocrlf=false \${\${SUBMODULES:#0}:+--recursive} -- \${URL} \${DIR} 2>&1); then - print_okay Installed + handle Installed else print_error 'Error during git clone' \${ERR} return 1 @@ -668,8 +698,8 @@ case \${ACTION} in fi if [[ \${TYPE} == tag ]]; then if [[ \${REV} == \$(command git -C \${DIR} describe --tags --exact-match 2>/dev/null) ]]; then - print_okay 'Already up to date' - return 0 + handle 'Already up to date' + return \${?} fi elif [[ -z \${REV} ]]; then # Get HEAD remote branch @@ -710,7 +740,7 @@ case \${ACTION} in return 1 fi fi - print_okay \${OUT} \${LOG} + handle \${OUT} \${LOG} ;; esac " ;; @@ -719,12 +749,12 @@ esac return 1 ;; esac - zsh -c ${zcmd} ${ztool} ${_zprintlevel} "${@[2,8]}" + zsh -c ${zcmd} ${ztool} ${_zprintlevel} "${@[2,9]}" } zimfw() { builtin emulate -L zsh -o EXTENDED_GLOB - local -r _zversion='1.8.0' zusage="Usage: %B${0}%b [%B-q%b|%B-v%b] + local -r _zversion='1.9.0-SNAPSHOT' zusage="Usage: %B${0}%b [%B-q%b|%B-v%b] Actions: %Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b. @@ -740,10 +770,10 @@ Actions: Use %B-v%b to also see the modules details. %Binit%b Same as %Binstall%b, but with output tailored to be used at terminal startup. %Binstall%b Install new modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to - also see their output, and see skipped modules. + also see their output, any on-pull output, and see skipped modules. %Buninstall%b Delete unused modules. Prompts for confirmation. Use %B-q%b for quiet uninstall. %Bupdate%b Update current modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b - to also see their output, and see skipped modules. + to also see their output, any on-pull output, and see skipped modules. %Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output. %Bversion%b Print zimfw version. @@ -785,7 +815,7 @@ Options: help) print -PR ${zusage} ;; info) _zimfw_info ;; list) - _zimfw_source_zimrc 3 && zargs -n 10 -- "${_zmodules_zargs[@]}" -- _zimfw_run_list && \ + _zimfw_source_zimrc 3 && zargs -n 11 -- "${_zmodules_zargs[@]}" -- _zimfw_run_list && \ _zimfw_list_unuseds ' (unused)' ;; init)