From e14ca42b2f706402f4dc2df95822e55802405ef8 Mon Sep 17 00:00:00 2001 From: Tharre Date: Tue, 5 Jul 2016 21:56:32 +0200 Subject: Add update functionality --- shell/_zshrc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'shell/_zshrc') diff --git a/shell/_zshrc b/shell/_zshrc index 8884395..9d84fed 100644 --- a/shell/_zshrc +++ b/shell/_zshrc @@ -15,7 +15,7 @@ ZSH_THEME="custom" # HYPHEN_INSENSITIVE="true" # Uncomment the following line to disable bi-weekly auto-update checks. -# DISABLE_AUTO_UPDATE="true" +DISABLE_AUTO_UPDATE="true" # Uncomment the following line to change how often to auto-update (in days). # export UPDATE_ZSH_DAYS=13 @@ -108,6 +108,26 @@ function 256color_test { done ) } +# update +function update_dotfiles() { + dotfiles="$HOME/dotfiles" + epoch_file="$dotfiles/.updated" + epoch_curr=$(date +'%s') + [ -e "$epoch_file" ] && epoch_old=$(<"$epoch_file") + epoch_diff=$(($epoch_curr - ${epoch_old:-0})) + max_time=$((60 * 60 * 24 * 7)) + + if [ $(($epoch_diff / $max_time)) -ne 0 ]; then + echo "Updating dotfiles ..." + + cd "$dotfiles" + git pull --rebase --stat origin master + echo $epoch_curr > "$epoch_file" + + echo "Finished." + fi +} + ## PATH export PATH=$PATH:$HOME/bin @@ -137,6 +157,8 @@ setopt EXTENDED_GLOB HISTSIZE=100000000 ## startup +update_dotfiles + if type "archey" > /dev/null; then archey # nice system information and arch logo fi -- cgit v1.2.3-70-g09d2