diff --git a/libozsh.zsh b/libozsh.zsh index e63b2c0..85569f9 100644 --- a/libozsh.zsh +++ b/libozsh.zsh @@ -35,6 +35,10 @@ function ozsh_load { fi } +function ozsh_write_update_date { + echo $(date +%Y-%m-%d) > "$OZSH_LASTUPDATE_FILE" +} + function ozsh_update { git -C $OZSH_HOME stash git -C $OZSH_HOME pull --rebase @@ -47,11 +51,17 @@ function ozsh_update { git -C $d pull --rebase done - echo $(date +%Y-%m-%d) > "$OZSH_LASTUPDATE_FILE" + ozsh_write_update_date } function ozsh_autoupdate { local timediff=$(( ( $(strftime -r %Y-%m-%d $(date +%Y-%m-%d)) - $(strftime -r %Y-%m-%d $(cat $OZSH_LASTUPDATE_FILE)) ) / 86400 )) + + if [ ! $? -eq 0 ]; then + # recreate the file if the command fails + ozsh_write_update_date + fi + if [ "$timediff" -ge "7" ]; then vared -p 'Would you like to update ozsh? [y/N]: ' -c answer if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then @@ -68,7 +78,7 @@ function ozsh_init { # create lastupdate file if not exist if [ ! -f $OZSH_LASTUPDATE_FILE ]; then - echo $(date +%Y-%m-%d) > $OZSH_LASTUPDATE_FILE + ozsh_write_update_date fi # load the datetime module