From 1341afe5254530daacf1332dc0faf6c53c280089 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Wed, 15 Jan 2020 12:35:30 -0500 Subject: [PATCH] Optional async check for latest version every 30 days, storing it in a .latest_version file. Also allow disabling this with: zstyle ':zim' disable-version-check yes --- .gitignore | 1 + CHANGELOG.md | 3 ++- README.md | 32 +++++++++++------------ src/stage2/40_zimfw_version_check.zsh.erb | 16 ++++++++++++ src/stage2/50_zimfw_info.zsh.erb | 8 +++--- src/stage2/80_zimfw.zsh.erb | 7 ++--- zimfw.zsh | 32 ++++++++++++++++------- 7 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 src/stage2/40_zimfw_version_check.zsh.erb diff --git a/.gitignore b/.gitignore index ffc0e3d..36d5242 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.zwc *.zwc.old /modules/ +.latest_version /init.zsh /init.zsh.old /login_init.zsh diff --git a/CHANGELOG.md b/CHANGELOG.md index 8482423..2d40a71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ 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`. +- Asynchronously check the latest version every 30 days. This can be disabled + with `zstyle ':zim' disable-version-check yes`. ### Changed - When upgrading, download latest release asset instead of raw file from the diff --git a/README.md b/README.md index 7980f2a..7340b94 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Installing Zim is easy: wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh Open a new terminal and you're done! Enjoy your Zsh IMproved! Take some time to -read about the [available modules] and tweak your `.zshrc` file. +read about the [available modules] and tweak your `~/.zshrc` file. If you have a different shell framework installed (like oh-my-zsh or prezto), *uninstall those first to prevent conflicts*. @@ -92,7 +92,7 @@ are equivalent: `name`, `zimfw/name`, `https://github.com/zimfw/name.git`. By default, the module name is the last component in the ``. Use the `-n|--name ` option to set a custom module name. -#### Repository options +Repository options: * `-b|--branch `: Use specified branch when installing and updating the module. Overrides the tag option. Default: `master`. @@ -100,7 +100,7 @@ By default, the module name is the last component in the ``. Use the module. Overrides the branch option. * `-z|--frozen`: Don't install or update the module. -#### Initialization options +Initialization options: * `-f|--fpath `: Add specified path to `fpath`. The path is relative to the module root directory. Default: `functions`, if the subdirectory exists. @@ -109,28 +109,28 @@ By default, the module name is the last component in the ``. Use the * `-s|--source `: Source specified file. The file path is relative to the module root directory. Default: the file with largest size matching `{init.zsh|module_name.{zsh|plugin.zsh|zsh-theme|sh}}`, if any exists. -* `-d|--disabled`: Don't use or uninstall the module. +* `-d|--disabled`: Don't initialize or uninstall the module. ### zimfw -Added new modules to `~/.zimrc`? Run: +Added new modules to `~/.zimrc`? Run `zimfw install`. - zimfw install +Removed modules from `~/.zimrc`? Run `zimfw uninstall`. -Removed modules from `~/.zimrc`? Run: +Want to update your modules to their latest revisions? Run `zimfw update`. - zimfw uninstall - -Want to update your modules to their latest revisions? Run: - - zimfw update - -Want to upgrade `~/.zim/zimfw.zsh` to the latest version? Run: - - zimfw upgrade +Want to upgrade `zimfw` to its latest version? Run `zimfw upgrade`. For more information about the `zimfw` tool, run `zimfw help`. +Settings +-------- + +By default, every 30 days `zimfw` will check if it has a new version available. +This can be disabled with: + + zstyle ':zim' disable-version-check yes + Uninstalling ------------ diff --git a/src/stage2/40_zimfw_version_check.zsh.erb b/src/stage2/40_zimfw_version_check.zsh.erb new file mode 100644 index 0000000..90b4113 --- /dev/null +++ b/src/stage2/40_zimfw_version_check.zsh.erb @@ -0,0 +1,16 @@ +_zimfw_version_check() { + if (( _zprintlevel > 0 )); then + setopt LOCAL_OPTIONS EXTENDED_GLOB + local -r ztarget=${ZIM_HOME}/.latest_version + # If .latest_version does not exist or was not modified in the last 30 days + if [[ ! -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} &! + fi + local -r zlatest_version=$(<${ztarget}) + if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then + print -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"$'\n' + fi + fi +} diff --git a/src/stage2/50_zimfw_info.zsh.erb b/src/stage2/50_zimfw_info.zsh.erb index 32b33b1..f50bf19 100644 --- a/src/stage2/50_zimfw_info.zsh.erb +++ b/src/stage2/50_zimfw_info.zsh.erb @@ -1,6 +1,6 @@ _zimfw_info() { - 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) + print -R 'zimfw 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 d5f7bb6..c6f7492 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -37,11 +37,8 @@ Options: 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 + if ! zstyle -t ':zim' disable-version-check; then + _zimfw_version_check fi case ${1} in diff --git a/zimfw.zsh b/zimfw.zsh index 1f4cc73..264f078 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -236,6 +236,23 @@ _zimfw_source_zimrc() { fi } +_zimfw_version_check() { + if (( _zprintlevel > 0 )); then + setopt LOCAL_OPTIONS EXTENDED_GLOB + local -r ztarget=${ZIM_HOME}/.latest_version + # If .latest_version does not exist or was not modified in the last 30 days + if [[ ! -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} &! + fi + local -r zlatest_version=$(<${ztarget}) + if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then + print -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"$'\n' + fi + fi +} + _zimfw_clean_compiled() { local zopt (( _zprintlevel > 0 )) && zopt='-v' @@ -259,10 +276,10 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'Zim version: '${_zversion}' (previous commit is be2be83)' - print -R 'ZIM_HOME: '${ZIM_HOME} - print -R 'Zsh version: '${ZSH_VERSION} - print -R 'System info: '$(command uname -a) + print -R 'zimfw version: '${_zversion}' (previous commit is 7fdf65c)' + print -R 'ZIM_HOME: '${ZIM_HOME} + print -R 'Zsh version: '${ZSH_VERSION} + print -R 'System info: '$(command uname -a) } _zimfw_uninstall() { @@ -338,11 +355,8 @@ Options: 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 + if ! zstyle -t ':zim' disable-version-check; then + _zimfw_version_check fi case ${1} in