check_for_upgrade.sh 1.2 KB
Newer Older
1
2
3
#!/usr/bin/env zsh

zmodload zsh/datetime
4

5
function _current_epoch() {
6
  echo $(( $EPOCHSECONDS / 60 / 60 / 24 ))
7
8
9
}

function _update_zsh_update() {
10
  echo "LAST_EPOCH=$(_current_epoch)" >! ~/.zsh-update
11
}
12

13
14
15
16
17
18
function _upgrade_zsh() {
  /usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
  # update the zsh file
  _update_zsh_update
}

Eric Danielson's avatar
Eric Danielson committed
19
20
21
22
23
24
epoch_target=$UPDATE_ZSH_DAYS
if [[ -z "$epoch_target" ]]; then
  # Default to old behavior
  epoch_target=13
fi

n.st's avatar
n.st committed
25
26
27
28
29
30
[ -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

31
32
if [ -f ~/.zsh-update ]
then
Gerhard Lazu's avatar
Gerhard Lazu committed
33
  . ~/.zsh-update
34
35
36
37
38

  if [[ -z "$LAST_EPOCH" ]]; then
    _update_zsh_update && return 0;
  fi

Christopher Chow's avatar
Christopher Chow committed
39
  epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
40
  if [ $epoch_diff -gt $epoch_target ]
41
  then
42
    if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
43
    then
44
45
46
47
48
      _upgrade_zsh
    else
      echo "[Oh My Zsh] Would you like to check for updates?"
      echo "Type Y to update oh-my-zsh: \c"
      read line
49
      if [ "$line" = Y ] || [ "$line" = y ]; then
50
        _upgrade_zsh
51
52
      else
        _update_zsh_update
53
      fi
54
55
    fi
  fi
nebirhos's avatar
nebirhos committed
56
57
58
else
  # create the zsh file
  _update_zsh_update
59
fi
60