summaryrefslogtreecommitdiff
path: root/tools/check_for_upgrade.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/check_for_upgrade.sh')
-rw-r--r--tools/check_for_upgrade.sh23
1 files changed, 14 insertions, 9 deletions
diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
index 0f8c9c391..881bc6c49 100644
--- a/tools/check_for_upgrade.sh
+++ b/tools/check_for_upgrade.sh
@@ -1,15 +1,17 @@
-#!/bin/sh
+#!/usr/bin/env zsh
+
+zmodload zsh/datetime
function _current_epoch() {
- echo $(($(date +%s) / 60 / 60 / 24))
+ echo $(( $EPOCHSECONDS / 60 / 60 / 24 ))
}
function _update_zsh_update() {
- echo "LAST_EPOCH=$(_current_epoch)" > ~/.zsh-update
+ echo "LAST_EPOCH=$(_current_epoch)" >! ~/.zsh-update
}
function _upgrade_zsh() {
- /usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
+ env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
# update the zsh file
_update_zsh_update
}
@@ -20,7 +22,12 @@ if [[ -z "$epoch_target" ]]; then
epoch_target=13
fi
-[ -f ~/.profile ] && source ~/.profile
+# Cancel upgrade if the current user doesn't have write permissions for the
+# oh-my-zsh directory.
+[[ -w "$ZSH" ]] || return 0
+
+# Cancel upgrade if git is unavailable on the system
+whence git >/dev/null || return 0
if [ -f ~/.zsh-update ]
then
@@ -37,10 +44,9 @@ then
then
_upgrade_zsh
else
- echo "[Oh My Zsh] Would you like to check for updates?"
- echo "Type Y to update oh-my-zsh: \c"
+ echo "[Oh My Zsh] Would you like to check for updates? [Y/n]: \c"
read line
- if [ "$line" = Y ] || [ "$line" = y ]; then
+ if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then
_upgrade_zsh
else
_update_zsh_update
@@ -51,4 +57,3 @@ else
# create the zsh file
_update_zsh_update
fi
-