8f6fbe238969ecb22fbdae75450a9f8705c9f979

Author
Håvard Bartnes <haavard.bartnes@gmail.com>
Committer
Carlo Sala <carlosalag@protonmail.com>
Date

Message

feat(upgrade): add verbosity settings

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Closes #11574
Closes #11579

Diff

  1diff --git a/README.md b/README.md
  2index 4042c8c268fe8750654c4c5798fb525f04c90f0f..4f0aeb7b4b77fd5432532fcf9d59a7e43a3995b7 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -317,6 +317,18 @@ zstyle ':omz:update' frequency 7
  6 zstyle ':omz:update' frequency 0
  7 ```
  8 
  9+### Updates verbosity
 10+
 11+You can also limit the update verbosity with the following settings:
 12+
 13+```sh
 14+zstyle ':omz:update' verbose default # default update prompt
 15+
 16+zstyle ':omz:update' verbose minimal # only few lines
 17+
 18+zstyle ':omz:update' verbose silent # only errors
 19+```
 20+
 21 ### Manual Updates
 22 
 23 If you'd like to update at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run:
 24diff --git a/lib/cli.zsh b/lib/cli.zsh
 25index fed00d21d6cb62a21aca38df6b2b25ceac48f058..ba3e39eb52bf3d489530354db4e076c82a3bd2cb 100644
 26--- a/lib/cli.zsh
 27+++ b/lib/cli.zsh
 28@@ -776,10 +776,11 @@ function _omz::update {
 29   local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD)
 30 
 31   # Run update script
 32+  zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
 33   if [[ "$1" != --unattended ]]; then
 34-    ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" --interactive || return $?
 35+    ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $?
 36   else
 37-    ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" || return $?
 38+    ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -v $verbose_mode || return $?
 39   fi
 40 
 41   # Update last updated file
 42diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
 43index 734714c94ca0ebdc0ce76ae3f8b7f992f782eb0e..81c371b3f50a0085fa022046750ad10e01471265 100644
 44--- a/tools/check_for_upgrade.sh
 45+++ b/tools/check_for_upgrade.sh
 46@@ -95,7 +95,8 @@ function update_last_updated_file() {
 47 }
 48 
 49 function update_ohmyzsh() {
 50-  if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive; then
 51+  zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
 52+  if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then
 53     update_last_updated_file
 54   fi
 55 }
 56diff --git a/tools/upgrade.sh b/tools/upgrade.sh
 57index 596a593025cfa3a57e0a66b40829823a965ae439..684ad894a2a4a1b011ea32feb41b07539c67dbec 100755
 58--- a/tools/upgrade.sh
 59+++ b/tools/upgrade.sh
 60@@ -12,6 +12,23 @@ esac
 61 
 62 cd "$ZSH"
 63 
 64+verbose_mode="default"
 65+interactive=false
 66+
 67+while getopts "v:i" opt; do
 68+  case $opt in
 69+    v)
 70+      if [[ $OPTARG == default || $OPTARG == minimal || $OPTARG == silent ]]; then
 71+        verbose_mode=$OPTARG
 72+      else
 73+        echo "[oh-my-zsh] update verbosity '$OPTARG' is not valid"
 74+        echo "[oh-my-zsh] valid options are 'default', 'minimal' and 'silent'"
 75+      fi
 76+      ;;
 77+    i) interactive=true ;;
 78+  esac
 79+done
 80+
 81 # Use colors, but only if connected to a terminal
 82 # and that terminal supports them.
 83 
 84@@ -203,7 +220,9 @@ git checkout -q "$branch" -- || exit 1
 85 last_commit=$(git rev-parse "$branch")
 86 
 87 # Update Oh My Zsh
 88-printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
 89+if [[ $verbose_mode != silent ]]; then
 90+  printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
 91+fi
 92 if LANG= git pull --quiet --rebase $remote $branch; then
 93   # Check if it was really updated or not
 94   if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
 95@@ -215,24 +234,30 @@ if LANG= git pull --quiet --rebase $remote $branch; then
 96     git config oh-my-zsh.lastVersion "$last_commit"
 97 
 98     # Print changelog to the terminal
 99-    if [[ "$1" = --interactive ]]; then
100+    if [[ interactive == true && $verbose_mode == default ]] ; then
101       "$ZSH/tools/changelog.sh" HEAD "$last_commit"
102     fi
103 
104-    printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog"
105+    if [[ $verbose_mode != silent ]]; then
106+      printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog"
107+    fi
108   fi
109 
110-  printf '%s         %s__      %s           %s        %s       %s     %s__   %s\n'      $RAINBOW $RESET
111-  printf '%s  ____  %s/ /_    %s ____ ___  %s__  __  %s ____  %s_____%s/ /_  %s\n'      $RAINBOW $RESET
112-  printf '%s / __ \\%s/ __ \\  %s / __ `__ \\%s/ / / / %s /_  / %s/ ___/%s __ \\ %s\n'  $RAINBOW $RESET
113-  printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s   / /_%s(__  )%s / / / %s\n'      $RAINBOW $RESET
114-  printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s   /___/%s____/%s_/ /_/  %s\n'    $RAINBOW $RESET
115-  printf '%s    %s        %s           %s /____/ %s       %s     %s          %s\n'      $RAINBOW $RESET
116-  printf '\n'
117-  printf "${BLUE}%s${RESET}\n\n" "$message"
118-  printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
119-  printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
120-  printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
121+  if [[ $verbose_mode == default ]]; then
122+    printf '%s         %s__      %s           %s        %s       %s     %s__   %s\n'      $RAINBOW $RESET
123+    printf '%s  ____  %s/ /_    %s ____ ___  %s__  __  %s ____  %s_____%s/ /_  %s\n'      $RAINBOW $RESET
124+    printf '%s / __ \\%s/ __ \\  %s / __ `__ \\%s/ / / / %s /_  / %s/ ___/%s __ \\ %s\n'  $RAINBOW $RESET
125+    printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s   / /_%s(__  )%s / / / %s\n'      $RAINBOW $RESET
126+    printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s   /___/%s____/%s_/ /_/  %s\n'    $RAINBOW $RESET
127+    printf '%s    %s        %s           %s /____/ %s       %s     %s          %s\n'      $RAINBOW $RESET
128+    printf '\n'
129+    printf "${BLUE}%s${RESET}\n\n" "$message"
130+    printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
131+    printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
132+    printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
133+  elif [[ $verbose_mode == minimal ]]; then
134+    printf "${BLUE}%s${RESET}\n" "$message"
135+  fi
136 else
137   ret=$?
138   printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'