41f13ccb0a5d04496605f69b7ae284d9d639b625

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Updating check_for_upgrade script to fix issue when the LAST_EPOCH file/value got corrupted. Closes #32

Diff

 1diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
 2index 5c212b6fa377b61c0baf76e7e68df1092088059e..c59ebaed48ebd8b7a3778c6d81f34126d101aa24 100644
 3--- a/tools/check_for_upgrade.sh
 4+++ b/tools/check_for_upgrade.sh
 5@@ -1,11 +1,22 @@
 6 #!/bin/sh
 7 
 8-current_epoch=$(($(date +%s) / 60 / 60 / 24))
 9+function _current_epoch() {
10+  echo $(($(date +%s) / 60 / 60 / 24))
11+}
12+
13+function _update_zsh_update() {
14+  echo "LAST_EPOCH=$(_current_epoch)" > ~/.zsh-update
15+}
16 
17 if [ -f ~/.zsh-update ]
18 then
19   . ~/.zsh-update
20-  epoch_diff=$(($current_epoch - $LAST_EPOCH))
21+
22+  if [[ -z "$LAST_EPOCH" ]]; then
23+    _update_zsh_update && return 0;
24+  fi
25+
26+  epoch_diff=$((${_current_epoch} - $LAST_EPOCH))
27   if [ $epoch_diff -gt 6 ]
28   then
29     echo "[Oh My Zsh] Would you like to check for updates?"
30@@ -15,14 +26,9 @@ then
31     then
32       /bin/sh $ZSH/tools/upgrade.sh
33     fi
34-
35-    # Set the last epoch to the current so that we don't ask for another week
36-    echo "LAST_EPOCH=${current_epoch}" > ~/.zsh-update
37   fi
38-else
39-  # TODO: refactor this so remove duplicates
40-  # Create the ~/.zsh-update file with the current epoch info
41-  echo "LAST_EPOCH=${current_epoch}" > ~/.zsh-update
42 fi
43 
44+# update the zsh file
45+_update_zsh_update
46