From be2be835604038e6574bc0c386eb4032ab399d38 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 13 Jan 2020 13:14:31 -0500 Subject: [PATCH] Check the latest version using `git ls-remote` which is being used to list the latest tag starting with `v`. Print a warning if it's different than the current version being used. --- CHANGELOG.md | 1 + src/stage2/20_guard.zsh.erb | 2 +- src/stage2/30_zmodule.zsh.erb | 5 ++--- src/stage2/50_zimfw_info.zsh.erb | 2 +- src/stage2/80_zimfw.zsh.erb | 21 ++++++++++++++------- zimfw.zsh | 30 ++++++++++++++++++------------ 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6437b6c..8482423 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `help` and `version` actions. - `-v` verbose option. Normal mode output is now cleaner and more focused. +- Check the latest version using `git ls-remote`. ### Changed - When upgrading, download latest release asset instead of raw file from the diff --git a/src/stage2/20_guard.zsh.erb b/src/stage2/20_guard.zsh.erb index fff3721..b6f778f 100644 --- a/src/stage2/20_guard.zsh.erb +++ b/src/stage2/20_guard.zsh.erb @@ -1,5 +1,5 @@ autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then - print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < <%= min_zsh_version %> are not supported. Update your Zsh." + print -u2 -PR "%F{red}${0}: Error starting Zim. You're using Zsh version %B${ZSH_VERSION}%b and versions < %B<%= min_zsh_version %>%b are not supported. Upgrade your Zsh.%f" return 1 fi diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 429cca0..3e144eb 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -1,6 +1,5 @@ zmodule() { - local -r zusage=" -Usage: %B${0}%b [%B-n%b|%B--name%b ] [options] + local -r zusage="Usage: %B${0}%b [%B-n%b|%B--name%b ] [options] Repository options: %B-b%b|%B--branch%b Use specified branch when installing and updating the module @@ -14,7 +13,7 @@ Startup options: %B-d%b|%B--disabled%b Don't use or uninstall the module " if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then - print -u2 -PR "%F{red}${0}: Must be called from %B<%= home %>/.zimrc%b%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Must be called from %B<%= home %>/.zimrc%b%f"$'\n\n'${zusage} return 1 fi if (( ! # )); then diff --git a/src/stage2/50_zimfw_info.zsh.erb b/src/stage2/50_zimfw_info.zsh.erb index 8c068b1..32b33b1 100644 --- a/src/stage2/50_zimfw_info.zsh.erb +++ b/src/stage2/50_zimfw_info.zsh.erb @@ -1,5 +1,5 @@ _zimfw_info() { - print 'Zim version: <%= version %> (previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)' + print -R 'Zim version: '${_zversion}' (previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index fc675bf..938d785 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|%B-v%b] + local -r _zversion='<%= version %>' + local -r zusage="Usage: %B${0}%b [%B-q%b|%B-v%b] Actions: %Bbuild%b Build init.zsh and login_init.zsh @@ -24,19 +24,26 @@ Options: local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts local -i _zprintlevel=1 if (( # > 2 )); then - print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage} return 1 elif (( # > 1 )); then case ${2} in -q) _zprintlevel=0 ;; -v) _zprintlevel=2 ;; *) - print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n\n'${zusage} return 1 ;; esac fi + if (( _zprintlevel > 0 )); then + local -r zlatestversion=$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*' | sed 's?^.*/v??' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n1) + if [[ ${_zversion} != ${zlatestversion} ]]; then + print -PR "%F{yellow}Latest zimfw version is %B${zlatestversion}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"$'\n' + fi + fi + case ${1} in install) ztool="<%= render_escaped("src/tools/install.zsh.erb") %>" @@ -57,7 +64,7 @@ Options: clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; compile) _zimfw_build_login_init && _zimfw_compile ;; - help) print -P ${zusage} ;; + help) print -PR ${zusage} ;; info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 @@ -72,9 +79,9 @@ Options: (( _zprintlevel-- )) _zimfw_build_login_init && _zimfw_compile ;; - version) print '<%= version %>' ;; + version) print -PR ${_zversion} ;; *) - print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n\n'${zusage} return 1 ;; esac diff --git a/zimfw.zsh b/zimfw.zsh index e4fa34e..90b3aa8 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -25,7 +25,7 @@ # SOFTWARE. autoload -Uz is-at-least && if ! is-at-least 5.2; then - print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." + print -u2 -PR "%F{red}${0}: Error starting Zim. You're using Zsh version %B${ZSH_VERSION}%b and versions < %B5.2%b are not supported. Upgrade your Zsh.%f" return 1 fi @@ -101,8 +101,7 @@ _zimfw_build() { } zmodule() { - local -r zusage=" -Usage: %B${0}%b [%B-n%b|%B--name%b ] [options] + local -r zusage="Usage: %B${0}%b [%B-n%b|%B--name%b ] [options] Repository options: %B-b%b|%B--branch%b Use specified branch when installing and updating the module @@ -116,7 +115,7 @@ Startup options: %B-d%b|%B--disabled%b Don't use or uninstall the module " if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then - print -u2 -PR "%F{red}${0}: Must be called from %B${ZDOTDIR:-${HOME}}/.zimrc%b%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Must be called from %B${ZDOTDIR:-${HOME}}/.zimrc%b%f"$'\n\n'${zusage} return 1 fi if (( ! # )); then @@ -260,7 +259,7 @@ _zimfw_compile() { } _zimfw_info() { - print 'Zim version: 1.1.0-SNAPSHOT (previous commit is 6806bea)' + print -R 'Zim version: '${_zversion}' (previous commit is dab4b87)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -301,8 +300,8 @@ _zimfw_upgrade() { } zimfw() { - local -r zusage=" -Usage: %B${0}%b [%B-q%b|%B-v%b] + local -r _zversion='1.1.0-SNAPSHOT' + local -r zusage="Usage: %B${0}%b [%B-q%b|%B-v%b] Actions: %Bbuild%b Build init.zsh and login_init.zsh @@ -326,19 +325,26 @@ Options: local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts local -i _zprintlevel=1 if (( # > 2 )); then - print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage} return 1 elif (( # > 1 )); then case ${2} in -q) _zprintlevel=0 ;; -v) _zprintlevel=2 ;; *) - print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n\n'${zusage} return 1 ;; esac fi + if (( _zprintlevel > 0 )); then + local -r zlatestversion=$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*' | sed 's?^.*/v??' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n1) + if [[ ${_zversion} != ${zlatestversion} ]]; then + print -PR "%F{yellow}Latest zimfw version is %B${zlatestversion}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"$'\n' + fi + fi + case ${1} in install) ztool="# This runs in a new shell @@ -439,7 +445,7 @@ fi clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; compile) _zimfw_build_login_init && _zimfw_compile ;; - help) print -P ${zusage} ;; + help) print -PR ${zusage} ;; info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 @@ -454,9 +460,9 @@ fi (( _zprintlevel-- )) _zimfw_build_login_init && _zimfw_compile ;; - version) print '1.1.0-SNAPSHOT' ;; + version) print -PR ${_zversion} ;; *) - print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n\n'${zusage} return 1 ;; esac