e093a4cf62d494dc46a8b68de1cb039c0bcf007a

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

fix(updater): correctly restart the zsh session when the update pulled changes

Diff

This diff is truncated to protect this page.

  1diff --git a/lib/cli.zsh b/lib/cli.zsh
  2index 30790bec72c911c7231085e73461637fcdf56fe3..e8ce261313a5ddeed3bf1ec0250b7fc384e34074 100644
  3--- a/lib/cli.zsh
  4+++ b/lib/cli.zsh
  5@@ -1,22 +1,22 @@
  6 #!/usr/bin/env zsh
  7 
  8 function omz {
  9-    [[ $# -gt 0 ]] || {
 10-        _omz::help
 11-        return 1
 12-    }
 13-
 14-    local command="$1"
 15-    shift
 16-
 17-    # Subcommand functions start with _ so that they don't
 18-    # appear as completion entries when looking for `omz`
 19-    (( $+functions[_omz::$command] )) || {
 20-        _omz::help
 21-        return 1
 22-    }
 23-
 24-    _omz::$command "$@"
 25+  [[ $# -gt 0 ]] || {
 26+    _omz::help
 27+    return 1
 28+  }
 29+
 30+  local command="$1"
 31+  shift
 32+
 33+  # Subcommand functions start with _ so that they don't
 34+  # appear as completion entries when looking for `omz`
 35+  (( $+functions[_omz::$command] )) || {
 36+    _omz::help
 37+    return 1
 38+  }
 39+
 40+  _omz::$command "$@"
 41 }
 42 
 43 function _omz {
 44@@ -69,292 +69,298 @@ EOF
 45 }
 46 
 47 function _omz::confirm {
 48-    # If question supplied, ask it before reading the answer
 49-    # NOTE: uses the logname of the caller function
 50-    if [[ -n "$1" ]]; then
 51-        _omz::log prompt "$1" "${${functrace[1]#_}%:*}"
 52-    fi
 53-
 54-    # Read one character
 55-    read -r -k 1
 56-
 57-    # If no newline entered, add a newline
 58-    if [[ "$REPLY" != $'\n' ]]; then
 59-        echo
 60-    fi
 61+  # If question supplied, ask it before reading the answer
 62+  # NOTE: uses the logname of the caller function
 63+  if [[ -n "$1" ]]; then
 64+    _omz::log prompt "$1" "${${functrace[1]#_}%:*}"
 65+  fi
 66+
 67+  # Read one character
 68+  read -r -k 1
 69+
 70+  # If no newline entered, add a newline
 71+  if [[ "$REPLY" != $'\n' ]]; then
 72+    echo
 73+  fi
 74 }
 75 
 76 function _omz::log {
 77-    # if promptsubst is set, a message with `` or $()
 78-    # will be run even if quoted due to `print -P`
 79-    setopt localoptions nopromptsubst
 80-
 81-    # $1 = info|warn|error|debug
 82-    # $2 = text
 83-    # $3 = (optional) name of the logger
 84-
 85-    local logtype=$1
 86-    local logname=${3:-${${functrace[1]#_}%:*}}
 87-
 88-    # Don't print anything if debug is not active
 89-    if [[ $logtype = debug && -z $_OMZ_DEBUG ]]; then
 90-        return
 91-    fi
 92-
 93-    # Choose coloring based on log type
 94-    case "$logtype" in
 95-        prompt) print -Pn "%S%F{blue}$logname%f%s: $2" ;;
 96-        debug) print -P "%F{white}$logname%f: $2" ;;
 97-        info) print -P "%F{green}$logname%f: $2" ;;
 98-        warn) print -P "%S%F{yellow}$logname%f%s: $2" ;;
 99-        error) print -P "%S%F{red}$logname%f%s: $2" ;;
100-    esac >&2
101+  # if promptsubst is set, a message with `` or $()
102+  # will be run even if quoted due to `print -P`
103+  setopt localoptions nopromptsubst
104+
105diff --git a/lib/functions.zsh b/lib/functions.zsh
106index f6f34e85125fe4082faec585ad86706bf3c23734..b0582b32b62ccff176624fae2f8bc8376e2475be 100644
107--- a/lib/functions.zsh
108+++ b/lib/functions.zsh
109@@ -15,11 +15,17 @@ function upgrade_oh_my_zsh() {
110 
111   # Run update script
112   env ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh"
113+  local ret=$?
114   # Update last updated file
115   zmodload zsh/datetime
116   echo "LAST_EPOCH=$(( EPOCHSECONDS / 60 / 60 / 24 ))" >! "${ZSH_CACHE_DIR}/.zsh-update"
117   # Remove update lock if it exists
118   command rm -rf "$ZSH/log/update.lock"
119+  # Restart the zsh session
120+  if [[ $ret -eq 0 ]]; then
121+    # Check whether to run a login shell
122+    [[ "$ZSH_ARGZERO" = -* ]] && exec -l "${ZSH_ARGZERO#-}" || exec "$ZSH_ARGZERO"
123+  fi
124 }
125 
126 function take() {