From 969e0c42f7e960eb13558308d56f2dd3b16e0aa8 Mon Sep 17 00:00:00 2001 From: Anton Zadvorny Date: Sun, 11 Aug 2019 18:47:25 +0300 Subject: [PATCH] Add zplug auto update plugin --- home/.zsh/plugins/autoupdate.zsh | 41 ++++++++++++++++++++++++++++++++ home/.zshrc | 5 ++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 home/.zsh/plugins/autoupdate.zsh diff --git a/home/.zsh/plugins/autoupdate.zsh b/home/.zsh/plugins/autoupdate.zsh new file mode 100755 index 0000000..2fdaf4f --- /dev/null +++ b/home/.zsh/plugins/autoupdate.zsh @@ -0,0 +1,41 @@ +_zplug-check-interval() { + now=$(date +%s) + if [ -f "${1}" ]; then + last_update=$(cat "${1}") + else + last_update=0 + fi + interval=$(expr ${now} - ${last_update}) + echo "${interval}" +} + +_zplug-check-for-updates() { + if [ -z "${ZPLUG_PLUGIN_UPDATE_DAYS}" ]; then + ZPLUG_PLUGIN_UPDATE_DAYS=14 + fi + + if [ -z "${ZPLUG_PLUGIN_UPDATE_FILE}" ]; then + ZPLUG_PLUGIN_UPDATE_FILE="${ZPLUG_HOME:-}/.zplug_plugin_lastupdate" + fi + + local day_seconds=$(expr 24 \* 60 \* 60) + local plugins_seconds=$(expr ${day_seconds} \* ${ZPLUG_PLUGIN_UPDATE_DAYS}) + + local last_plugin=$(_zplug-check-interval ${ZPLUG_PLUGIN_UPDATE_FILE}) + + if [ ${last_plugin} -gt ${plugins_seconds} ]; then + echo "It has been $(expr ${last_plugin} / $day_seconds) days since your zplug plugins were updated" + zplug update + + date +%s >! ${ZPLUG_PLUGIN_UPDATE_FILE} + zplug clean --force + fi +} + +zmodload zsh/system +lockfile=${ZPLUG_HOME:-~}/.zplug_autoupdate_lock +touch $lockfile +if ! which zsystem &> /dev/null || zsystem flock -t 1 $lockfile; then + _zplug-check-for-updates + command rm -f $lockfile +fi diff --git a/home/.zshrc b/home/.zshrc index fa03404..16c82d4 100644 --- a/home/.zshrc +++ b/home/.zshrc @@ -37,8 +37,9 @@ zplug "plugins/asdf", from:oh-my-zsh zplug "zsh-users/zsh-completions" zplug "zsh-users/zsh-syntax-highlighting", defer:2 -zplug "~/.zsh/cmd", from:local, use:'(*).sh', as:command, rename-to:'$1' -zplug "~/.zsh/themes", from:local, use:cheetah.zsh-theme, as:theme +zplug "~/.zsh/plugins", from:local +zplug "~/.zsh/cmd", from:local, use:'(*).sh', as:command, rename-to:'$1' +zplug "~/.zsh/themes", from:local, use:cheetah.zsh-theme, as:theme if [[ $OSTYPE == *darwin* ]]; then zplug "plugins/osx", from:oh-my-zsh