-
-
Save gwarf/09afddb8741a7ea478ce53aafe20b777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2014-2015 Joe Block <[email protected]> | |
# | |
# 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