5 Commits 1ed8d4b555 ... d17ca487a4

Author SHA1 Message Date
  Martin Hans d17ca487a4 fix(history): add `t` option to history wrapper (#12365) 2 weeks ago
  Marc Cornellà 80a651a6df chore(updater): small typo 2 weeks ago
  Marc Cornellà 56cfcb44e7 fix(updater): abort update if `$ZSH` is not a git repository 2 weeks ago
  Marc Cornellà c262ffbb68 fix(update): define `$ZSH` if undefined (#12273) 2 weeks ago
  Marc Cornellà eafa78217d fix(history): fix `history -c` (#12362) 2 weeks ago
4 changed files with 28 additions and 11 deletions
  1. 11 1
      lib/cli.zsh
  2. 5 5
      lib/history.zsh
  3. 6 4
      tools/check_for_upgrade.sh
  4. 6 1
      tools/upgrade.sh

+ 11 - 1
lib/cli.zsh

@@ -773,7 +773,17 @@ function _omz::theme::use {
 }
 
 function _omz::update {
-  local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD)
+  # Check if git command is available
+  (( $+commands[git] )) || {
+    _omz::log error "git is not installed. Aborting..."
+    return 1
+  }
+
+  local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)
+  [[ $? -eq 0 ]] || {
+    _omz::log error "\`$ZSH\` is not a git directory. Aborting..."
+    return 1
+  }
 
   # Run update script
   zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default

+ 5 - 5
lib/history.zsh

@@ -2,16 +2,16 @@
 function omz_history {
   # parse arguments and remove from $@
   local clear list stamp
-  zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp
+  zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp t:=stamp
 
-  if [[ $# -eq 0 ]]; then
-    # if no arguments provided, show full history starting from 1
-    builtin fc $stamp -l 1
-  elif [[ -n "$clear" ]]; then
+  if [[ -n "$clear" ]]; then
     # if -c provided, clobber the history file
     echo -n >| "$HISTFILE"
     fc -p "$HISTFILE"
     echo >&2 History file deleted.
+  elif [[ $# -eq 0 ]]; then
+    # if no arguments provided, show full history starting from 1
+    builtin fc $stamp -l 1
   else
     # otherwise, run `fc -l` with a custom format
     builtin fc $stamp -l "$@"

+ 6 - 4
tools/check_for_upgrade.sh

@@ -20,14 +20,16 @@ zstyle -s ':omz:update' mode update_mode || {
 }
 
 # Cancel update if:
-# - the automatic update is disabled.
-# - the current user doesn't have write permissions nor owns the $ZSH directory.
+# - the automatic update is disabled
+# - the current user doesn't have write permissions nor owns the $ZSH directory
 # - is not run from a tty
-# - git is unavailable on the system.
+# - git is unavailable on the system
+# - $ZSH is not a git repository
 if [[ "$update_mode" = disabled ]] \
    || [[ ! -w "$ZSH" || ! -O "$ZSH" ]] \
    || [[ ! -t 1 ]] \
-   || ! command git --version 2>&1 >/dev/null; then
+   || ! command git --version 2>&1 >/dev/null \
+   || (builtin cd -q "$ZSH"; ! command git rev-parse --is-inside-work-tree &>/dev/null); then
   unset update_mode
   return
 fi

+ 6 - 1
tools/upgrade.sh

@@ -10,9 +10,14 @@ fi
 
 # Protect against unwanted sourcing
 case "$ZSH_EVAL_CONTEXT" in
-  *:file) echo "error: this file should not be sourced" && return ;;
+  *:file) echo "error: this file should not be sourced" && return 1 ;;
 esac
 
+# Define "$ZSH" if not defined -- in theory this should be `export`ed by the calling script
+if [[ -z "$ZSH" ]]; then
+  ZSH="${0:a:h:h}"
+fi
+
 cd "$ZSH"
 
 verbose_mode="default"