Adds options for update check

If the env variable UPDATE_CHECK is set to "daily", "weekly" or
"monthly", there will be a message if you're late on your update.

If the env variable UPDATE_CHECK_ALWAYS is set to "true", you will get a
message telling you that your system is up to date.
This commit is contained in:
Thomas Forgione 2019-02-01 15:18:33 +01:00
parent b71d8f6e6d
commit 0fa53b8b95
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 33 additions and 5 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
zsh/extraconfig.zsh
zsh/env.zsh
.data

View File

@ -1,3 +1,13 @@
_date_format() {
case $UPDATE_CHECK in
"daily") echo +%d/%m/%Y;;
"weekly") echo +%V/%Y;;
"monthly") echo +%m/%Y;;
esac
}
_check_date_file() {
mkdir -p ~/.config/dotfiles/.data
touch ~/.config/dotfiles/.data/update_date
@ -32,14 +42,15 @@ _sentence() {
}
_check_date() {
_check_date_file
old_date=`cat ~/.config/dotfiles/.data/update_date`
new_date=`date +%d/%m/%y`
new_date=`date $1`
if [ "$new_date" != "$old_date" ]; then
_sentence not_updated
else
elif [ "$UPDATE_CHECK_ALWAYS" == "true" ]; then
_sentence updated
fi
}
@ -207,6 +218,19 @@ update() {
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
echo "\033[32;1m=== Update finished in $formatted ===\033[0m"
_check_date_file
date +%d/%m/%y > ~/.config/dotfiles/.data/update_date
format=`_date_format`
if [ $? -eq 0 ]; then
_check_date_file
date $format > ~/.config/dotfiles/.data/update_date
fi
}
# Spawn anonymous function
function() {
local format=`_date_format`
if [ "$format" != "" ]; then
_check_date $format
fi
}

4
zshrc
View File

@ -10,6 +10,10 @@ ZSH_CUSTOM=$HOME/.config/dotfiles/zsh/oh-my-zsh
ZSH_THEME="laptop"
if [ -f $DOTFILES/zsh/env.zsh ]; then
source $DOTFILES/zsh/env.zsh
fi
source $DOTFILES/zsh/config.zsh
source $DOTFILES/zsh/path.zsh
source $DOTFILES/zsh/exports.zsh