Skip to content

Instantly share code, notes, and snippets.

@notyal
Last active October 20, 2017 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save notyal/9a019b8a2c4ae3d9e4fa4109154ad1b7 to your computer and use it in GitHub Desktop.
Save notyal/9a019b8a2c4ae3d9e4fa4109154ad1b7 to your computer and use it in GitHub Desktop.
# Copyright 2014-2015 Joe Block <jpb@unixorn.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
_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=7
fi
if [ -z "${ZPLUG_PLUGIN_RECEIPT_F}" ]; then
ZPLUG_PLUGIN_RECEIPT_F="${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_RECEIPT_F})
if [ ${last_plugin} -gt ${plugins_seconds} ]; then
if [ ! -z "${ZPLUG_AUTOUPDATE_VERBOSE}" ]; then
echo "It has been $(expr ${last_plugin} / $day_seconds) days since your zplug plugins were updated"
echo "Updating plugins"
fi
zplug update
date +%s >! ${ZPLUG_PLUGIN_RECEIPT_F}
## Use this time to clean out old plugins
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment