Add version-check action
And don't run the dumping of the .latest_version file in _zimfw_version_check in the background (with `&!`) anymore. See #503
This commit is contained in:
parent
222c971542
commit
a34b8dab64
4 changed files with 42 additions and 36 deletions
|
@ -1,18 +1,16 @@
|
||||||
_zimfw_version_check() {
|
_zimfw_version_check() {
|
||||||
if (( _zprintlevel > 0 )); then
|
if [[ ${1} -ne 0 || ! -f ${_zversion_target} ]]; then
|
||||||
local -r ztarget=${ZIM_HOME}/.latest_version
|
# Get latest version (get all `v*` tags from repo, delete `*v` from beginning,
|
||||||
# If .latest_version does not exist or was not modified in the last 30 days
|
# sort in descending `O`rder `n`umerically, and get the `[1]` first)
|
||||||
if [[ -w ${ztarget:h} && ! -f ${ztarget}(#qNm-30) ]]; then
|
local tags
|
||||||
# Get latest version (get all `v*` tags from repo, delete `*v` from beginning,
|
tags=$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*') || return 1
|
||||||
# sort in descending `O`rder `n`umerically, and get the `[1]` first)
|
>! ${_zversion_target} <<<${${(On)${(f)tags}##*v}[1]} || return 1
|
||||||
print -R ${${(On)${(f)"$(command git ls-remote --tags --refs \
|
fi
|
||||||
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${ztarget} &!
|
local -r zlatest_version=$(<${_zversion_target})
|
||||||
fi
|
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
|
||||||
if [[ -f ${ztarget} ]]; then
|
if (( _zprintlevel > 0 )); then
|
||||||
local -r zlatest_version=$(<${ztarget})
|
print -u2 -PR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"
|
||||||
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
|
|
||||||
print -u2 -PlR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f" ''
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
zimfw() {
|
zimfw() {
|
||||||
builtin emulate -L zsh -o EXTENDED_GLOB
|
builtin emulate -L zsh -o EXTENDED_GLOB
|
||||||
local -r _zversion='<%= version %>' zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
|
local -r _zversion='<%= version %>' _zversion_target=${ZIM_HOME}/.latest_version zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
|
||||||
|
|
||||||
Actions:
|
Actions:
|
||||||
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
|
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
|
||||||
|
@ -21,6 +21,7 @@ Actions:
|
||||||
output, any on-pull output and skipped modules.
|
output, any on-pull output and skipped modules.
|
||||||
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
|
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
|
||||||
%Bversion%b Print zimfw version.
|
%Bversion%b Print zimfw version.
|
||||||
|
%Bversion-check%b Check if a new version of zimfw is available.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
%B-q%b Quiet (yes to prompts and only outputs errors)
|
%B-q%b Quiet (yes to prompts and only outputs errors)
|
||||||
|
@ -43,8 +44,11 @@ Options:
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! zstyle -t ':zim' disable-version-check; then
|
if ! zstyle -t ':zim' disable-version-check && [[ ${1} != version-check ]]; then
|
||||||
_zimfw_version_check
|
# If .latest_version does not exist or was not modified in the last 30 days
|
||||||
|
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
|
||||||
|
_zimfw_version_check ${zversion_check_force}
|
||||||
|
print
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local _zrestartmsg=' Restart your terminal for changes to take effect.'
|
local _zrestartmsg=' Restart your terminal for changes to take effect.'
|
||||||
|
@ -85,6 +89,7 @@ Options:
|
||||||
_zimfw_source_zimrc 2 && _zimfw_compile
|
_zimfw_source_zimrc 2 && _zimfw_compile
|
||||||
;;
|
;;
|
||||||
version) print -PR ${_zversion} ;;
|
version) print -PR ${_zversion} ;;
|
||||||
|
version-check) _zimfw_version_check 1 ;;
|
||||||
*)
|
*)
|
||||||
print -u2 -PlR "%F{red}${0}: Unknown action ${1}%f" '' ${zusage}
|
print -u2 -PlR "%F{red}${0}: Unknown action ${1}%f" '' ${zusage}
|
||||||
return 2
|
return 2
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Zim
|
||||||
:clear_line, :ellipsis, :okay, :warn, :error, :done, :failed
|
:clear_line, :ellipsis, :okay, :warn, :error, :done, :failed
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@version = "1.11.3"
|
@version = "1.12.0-SNAPSHOT"
|
||||||
@home = "${ZDOTDIR:-${HOME}}"
|
@home = "${ZDOTDIR:-${HOME}}"
|
||||||
@min_zsh_version = "5.2"
|
@min_zsh_version = "5.2"
|
||||||
# Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo
|
# Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo
|
||||||
|
|
39
zimfw.zsh
39
zimfw.zsh
|
@ -383,21 +383,19 @@ _zimfw_list_unuseds() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_version_check() {
|
_zimfw_version_check() {
|
||||||
if (( _zprintlevel > 0 )); then
|
if [[ ${1} -ne 0 || ! -f ${_zversion_target} ]]; then
|
||||||
local -r ztarget=${ZIM_HOME}/.latest_version
|
# Get latest version (get all `v*` tags from repo, delete `*v` from beginning,
|
||||||
# If .latest_version does not exist or was not modified in the last 30 days
|
# sort in descending `O`rder `n`umerically, and get the `[1]` first)
|
||||||
if [[ -w ${ztarget:h} && ! -f ${ztarget}(#qNm-30) ]]; then
|
local tags
|
||||||
# Get latest version (get all `v*` tags from repo, delete `*v` from beginning,
|
tags=$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*') || return 1
|
||||||
# sort in descending `O`rder `n`umerically, and get the `[1]` first)
|
>! ${_zversion_target} <<<${${(On)${(f)tags}##*v}[1]} || return 1
|
||||||
print -R ${${(On)${(f)"$(command git ls-remote --tags --refs \
|
fi
|
||||||
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${ztarget} &!
|
local -r zlatest_version=$(<${_zversion_target})
|
||||||
fi
|
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
|
||||||
if [[ -f ${ztarget} ]]; then
|
if (( _zprintlevel > 0 )); then
|
||||||
local -r zlatest_version=$(<${ztarget})
|
print -u2 -PR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"
|
||||||
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
|
|
||||||
print -u2 -PlR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f" ''
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +434,7 @@ _zimfw_compile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_info() {
|
_zimfw_info() {
|
||||||
print -R 'zimfw version: '${_zversion}' (built at 2023-02-26 00:43:41 UTC, previous commit is 6a24459)'
|
print -R 'zimfw version: '${_zversion}' (built at 2023-03-23 22:29:09 UTC, previous commit is 222c971)'
|
||||||
print -R 'OSTYPE: '${OSTYPE}
|
print -R 'OSTYPE: '${OSTYPE}
|
||||||
print -R 'TERM: '${TERM}
|
print -R 'TERM: '${TERM}
|
||||||
print -R 'TERM_PROGRAM: '${TERM_PROGRAM}
|
print -R 'TERM_PROGRAM: '${TERM_PROGRAM}
|
||||||
|
@ -823,7 +821,7 @@ esac
|
||||||
|
|
||||||
zimfw() {
|
zimfw() {
|
||||||
builtin emulate -L zsh -o EXTENDED_GLOB
|
builtin emulate -L zsh -o EXTENDED_GLOB
|
||||||
local -r _zversion='1.11.3' zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
|
local -r _zversion='1.12.0-SNAPSHOT' _zversion_target=${ZIM_HOME}/.latest_version zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
|
||||||
|
|
||||||
Actions:
|
Actions:
|
||||||
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
|
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
|
||||||
|
@ -844,6 +842,7 @@ Actions:
|
||||||
output, any on-pull output and skipped modules.
|
output, any on-pull output and skipped modules.
|
||||||
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
|
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
|
||||||
%Bversion%b Print zimfw version.
|
%Bversion%b Print zimfw version.
|
||||||
|
%Bversion-check%b Check if a new version of zimfw is available.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
%B-q%b Quiet (yes to prompts and only outputs errors)
|
%B-q%b Quiet (yes to prompts and only outputs errors)
|
||||||
|
@ -866,8 +865,11 @@ Options:
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! zstyle -t ':zim' disable-version-check; then
|
if ! zstyle -t ':zim' disable-version-check && [[ ${1} != version-check ]]; then
|
||||||
_zimfw_version_check
|
# If .latest_version does not exist or was not modified in the last 30 days
|
||||||
|
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
|
||||||
|
_zimfw_version_check ${zversion_check_force}
|
||||||
|
print
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local _zrestartmsg=' Restart your terminal for changes to take effect.'
|
local _zrestartmsg=' Restart your terminal for changes to take effect.'
|
||||||
|
@ -908,6 +910,7 @@ Options:
|
||||||
_zimfw_source_zimrc 2 && _zimfw_compile
|
_zimfw_source_zimrc 2 && _zimfw_compile
|
||||||
;;
|
;;
|
||||||
version) print -PR ${_zversion} ;;
|
version) print -PR ${_zversion} ;;
|
||||||
|
version-check) _zimfw_version_check 1 ;;
|
||||||
*)
|
*)
|
||||||
print -u2 -PlR "%F{red}${0}: Unknown action ${1}%f" '' ${zusage}
|
print -u2 -PlR "%F{red}${0}: Unknown action ${1}%f" '' ${zusage}
|
||||||
return 2
|
return 2
|
||||||
|
|
Loading…
Reference in a new issue