check_for_upgrade.sh 862 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. function _current_epoch() {
  3. echo $(($(date +%s) / 60 / 60 / 24))
  4. }
  5. function _update_zsh_update() {
  6. echo "LAST_EPOCH=$(_current_epoch)" > ~/.zsh-update
  7. }
  8. function _upgrade_zsh() {
  9. /usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
  10. # update the zsh file
  11. _update_zsh_update
  12. }
  13. if [ -f ~/.zsh-update ]
  14. then
  15. . ~/.zsh-update
  16. if [[ -z "$LAST_EPOCH" ]]; then
  17. _update_zsh_update && return 0;
  18. fi
  19. epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
  20. if [ $epoch_diff -gt 13 ]
  21. then
  22. if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
  23. then
  24. _upgrade_zsh
  25. else
  26. echo "[Oh My Zsh] Would you like to check for updates?"
  27. echo "Type Y to update oh-my-zsh: \c"
  28. read line
  29. if [ "$line" = Y ] || [ "$line" = y ]
  30. then
  31. _upgrade_zsh
  32. fi
  33. fi
  34. fi
  35. else
  36. # create the zsh file
  37. _update_zsh_update
  38. fi