check_for_upgrade.sh 895 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 ]; then
  30. _upgrade_zsh
  31. else
  32. _update_zsh_update
  33. fi
  34. fi
  35. fi
  36. else
  37. # create the zsh file
  38. _update_zsh_update
  39. fi