From 8724686e859d1ec9f11de2132b5bf17330b86e8b Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 16 May 2020 20:22:22 -0500 Subject: [PATCH] Don't depend on `cmp` and `xargs` as they requires busybox or diffutils and findutils. Use `cksum` and `zargs` instead. Fixes #393 --- CHANGELOG.md | 7 ++++++- src/stage2/28_zimfw_mv.zsh.erb | 3 ++- src/stage2/30_zmodule.zsh.erb | 4 ++-- src/stage2/31_zimfw_source_zimrc.zsh.erb | 4 ++-- src/stage2/80_zimfw.zsh.erb | 7 ++++--- zimfw.zsh | 20 +++++++++++--------- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb68c70..668efcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -_No unreleased changes._ +### Changed +- Use `cksum` instead of `cmp`, and `zargs` instead of `xargs`, so we don't + depend on busybox or diffutils and findutils. + +### Fixed +- Error messages and the `zmodule` usage text. ## [1.1.1] - 2020-01-26 diff --git a/src/stage2/28_zimfw_mv.zsh.erb b/src/stage2/28_zimfw_mv.zsh.erb index 254d817..1e32730 100644 --- a/src/stage2/28_zimfw_mv.zsh.erb +++ b/src/stage2/28_zimfw_mv.zsh.erb @@ -1,5 +1,6 @@ _zimfw_mv() { - if command cmp -s ${2} ${1}; then + local -a cklines=(${(f)"$(command cksum ${@})"}) + if [[ ${${(z)cklines[1]}[1,2]} == ${${(z)cklines[2]}[1,2]} ]]; then _zimfw_print -PR "<%= okay %>%B${2}:%b Already up to date" else if [[ -e ${2} ]]; then diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 81c090e..0ee721b 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -108,9 +108,9 @@ Initialization options: esac shift done - if (( _zprepare_xargs )); then + if (( _zprepare_zargs )); then if (( ! zfrozen )); then - _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zprintlevel}$'\0' + _zmodules_zargs+=(${zmodule} ${zdir} ${zurl} ${ztype} ${zrev} ${_zprintlevel}) fi else if (( zdisabled )); then diff --git a/src/stage2/31_zimfw_source_zimrc.zsh.erb b/src/stage2/31_zimfw_source_zimrc.zsh.erb index a6b8966..bc90bee 100644 --- a/src/stage2/31_zimfw_source_zimrc.zsh.erb +++ b/src/stage2/31_zimfw_source_zimrc.zsh.erb @@ -1,12 +1,12 @@ _zimfw_source_zimrc() { local -r ztarget=<%= home %>/.zimrc - local -ri _zprepare_xargs=${1} + local -ri _zprepare_zargs=${1} local -i _zfailed=0 if ! source ${ztarget} || (( _zfailed )); then print -u2 -PR "%F{red}<%= failed %>Failed to source %B${ztarget}%b%f" return 1 fi - if (( _zprepare_xargs && ! ${#_zmodules_xargs} )); then + if (( _zprepare_zargs && ! ${#_zmodules_zargs} )); then print -u2 -PR "%F{red}<%= failed %>No modules defined in %B${ztarget}%b%f" return 1 fi diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 437f78b..9ef3078 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -20,8 +20,8 @@ Options: %B-q%b Quiet, only outputs errors %B-v%b Verbose " - local ztool _zmodules_xargs - local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts + local ztool + local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts _zmodules_zargs local -i _zprintlevel=1 if (( # > 2 )); then print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage} @@ -65,7 +65,8 @@ Options: info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 - print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ + autoload -Uz zargs && \ + zargs -n 9 -P 10 -- ${_zmodules_zargs} -- zsh -c ${ztool} ${1} && \ _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 diff --git a/zimfw.zsh b/zimfw.zsh index aa8c555..17d4a17 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -37,7 +37,8 @@ _zimfw_print() { } _zimfw_mv() { - if command cmp -s ${2} ${1}; then + local -a cklines=(${(f)"$(command cksum ${@})"}) + if [[ ${${(z)cklines[1]}[1,2]} == ${${(z)cklines[2]}[1,2]} ]]; then _zimfw_print -PR "%F{green})%f %B${2}:%b Already up to date" else if [[ -e ${2} ]]; then @@ -208,9 +209,9 @@ Initialization options: esac shift done - if (( _zprepare_xargs )); then + if (( _zprepare_zargs )); then if (( ! zfrozen )); then - _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zprintlevel}$'\0' + _zmodules_zargs+=(${zmodule} ${zdir} ${zurl} ${ztype} ${zrev} ${_zprintlevel}) fi else if (( zdisabled )); then @@ -240,13 +241,13 @@ Initialization options: _zimfw_source_zimrc() { local -r ztarget=${ZDOTDIR:-${HOME}}/.zimrc - local -ri _zprepare_xargs=${1} + local -ri _zprepare_zargs=${1} local -i _zfailed=0 if ! source ${ztarget} || (( _zfailed )); then print -u2 -PR "%F{red}Failed to source %B${ztarget}%b%f" return 1 fi - if (( _zprepare_xargs && ! ${#_zmodules_xargs} )); then + if (( _zprepare_zargs && ! ${#_zmodules_zargs} )); then print -u2 -PR "%F{red}No modules defined in %B${ztarget}%b%f" return 1 fi @@ -294,7 +295,7 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (previous commit is d1103f3)' + print -R 'zimfw version: '${_zversion}' (previous commit is 7e369ef)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -359,8 +360,8 @@ Options: %B-q%b Quiet, only outputs errors %B-v%b Verbose " - local ztool _zmodules_xargs - local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts + local ztool + local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts _zmodules_zargs local -i _zprintlevel=1 if (( # > 2 )); then print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage} @@ -482,7 +483,8 @@ fi info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 - print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ + autoload -Uz zargs && \ + zargs -n 9 -P 10 -- ${_zmodules_zargs} -- zsh -c ${ztool} ${1} && \ _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