From 163d36b61b2325fc090cc18611f25bd9caf8cfcb Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Fri, 19 Mar 2021 18:14:31 -0500 Subject: [PATCH] Use Zsh scripting instead of sed, sort and tail `foo | sed 's?^.*/v??' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n1` is the same as `${${(On)${(f)"$(foo)"}##*v}[1]}`. We don't want to depend on external tools that might not be available in all platforms. --- src/stage2/40_zimfw_version_check.zsh.erb | 6 +++--- zimfw.zsh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/stage2/40_zimfw_version_check.zsh.erb b/src/stage2/40_zimfw_version_check.zsh.erb index f33d7a1..6596194 100644 --- a/src/stage2/40_zimfw_version_check.zsh.erb +++ b/src/stage2/40_zimfw_version_check.zsh.erb @@ -4,9 +4,9 @@ _zimfw_version_check() { local -r ztarget=${ZIM_HOME}/.latest_version # If .latest_version does not exist or was not modified in the last 30 days if [[ -w ${ztarget:h} && ! -f ${ztarget}(#qNm-30) ]]; then - command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*' | \ - command sed 's?^.*/v??' | command sort -n -t. -k1,1 -k2,2 -k3,3 | \ - command tail -n1 >! ${ztarget} &! + # Get latest version (get all `v*` tags from repo, delete `*v` from beginning, sort in descending `O`rder + # `n`umerically, and get the `[1]` first) + print ${${(On)${(f)"$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*')"}##*v}[1]} >! ${ztarget} &! fi if [[ -f ${ztarget} ]]; then local -r zlatest_version=$(<${ztarget}) diff --git a/zimfw.zsh b/zimfw.zsh index 5af8ee5..3b2004e 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -290,9 +290,9 @@ _zimfw_version_check() { local -r ztarget=${ZIM_HOME}/.latest_version # If .latest_version does not exist or was not modified in the last 30 days if [[ -w ${ztarget:h} && ! -f ${ztarget}(#qNm-30) ]]; then - command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*' | \ - command sed 's?^.*/v??' | command sort -n -t. -k1,1 -k2,2 -k3,3 | \ - command tail -n1 >! ${ztarget} &! + # Get latest version (get all `v*` tags from repo, delete `*v` from beginning, sort in descending `O`rder + # `n`umerically, and get the `[1]` first) + print ${${(On)${(f)"$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*')"}##*v}[1]} >! ${ztarget} &! fi if [[ -f ${ztarget} ]]; then local -r zlatest_version=$(<${ztarget}) @@ -328,7 +328,7 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (built at 2021-03-19 22:13:04 UTC, previous commit is f7c0bbe)' + print -R 'zimfw version: '${_zversion}' (built at 2021-03-19 23:11:36 UTC, previous commit is 65783e6)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a)