1bb402190d53c118f47a0851f5714dd4faa52809

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

Message

lib: add plugin and theme subcommands and fix `omz pr clean`

- Add plugin and theme subcommand

  Fixes #8961

- Add confirmation prompt to `omz pr clean` command

- Correct behavior on invalid answers on confirmation prompts

  If an invalid option is supplied, don't proceed with the potentially
  destructive action.

Co-authored-by: Rishabh Bohra <rishabhbohra01@gmail.com>

Diff

This diff is truncated to protect this page.

  1diff --git a/lib/cli.zsh b/lib/cli.zsh
  2index c1ae2bdf2b6bbdc545145400b72e9205e5364cf9..0c0f3f623604b2e482ce3a9eff990f2bddd04a1d 100644
  3--- a/lib/cli.zsh
  4+++ b/lib/cli.zsh
  5@@ -23,17 +23,28 @@ function _omz {
  6     local -a cmds subcmds
  7     cmds=(
  8         'help:Usage information'
  9+        'plugin:Commands for Oh My Zsh plugins management'
 10+        'pr:Commands for Oh My Zsh Pull Requests management'
 11+        'theme:Commands for Oh My Zsh themes management'
 12         'update:Update Oh My Zsh'
 13-        'pr:Commands for Oh My Zsh Pull Requests'
 14     )
 15 
 16     if (( CURRENT == 2 )); then
 17         _describe 'command' cmds
 18     elif (( CURRENT == 3 )); then
 19         case "$words[2]" in
 20-            pr) subcmds=( 'test:Test a Pull Request' 'clean:Delete all Pull Request branches' )
 21+            plugin) subcmds=('list:List plugins')
 22+                _describe 'command' subcmds ;;
 23+            pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches')
 24+                _describe 'command' subcmds ;;
 25+            theme) subcmds=('use:Load a theme' 'list:List themes')
 26                 _describe 'command' subcmds ;;
 27         esac
 28+    elif (( CURRENT == 4 )); then
 29+        case "$words[2]::$words[3]" in
 30+            theme::use) compadd "$ZSH"/themes/*.zsh-theme(.N:t:r) \
 31+                "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::) ;;
 32+        esac
 33     fi
 34 
 35     return 0
 36@@ -49,23 +60,40 @@ Usage: omz <command> [options]
 37 Available commands:
 38 
 39     help                Print this help message
 40+    pr <command>        Commands for Oh My Zsh Pull Requests management
 41+    theme <command>     Commands for Oh My Zsh themes management
 42     update              Update Oh My Zsh
 43-    pr <command>        Commands for Oh My Zsh Pull Requests
 44 
 45 EOF
 46 }
 47 
 48+function _omz::confirm {
 49+    # If question supplied, ask it before reading the answer
 50+    # NOTE: uses the logname of the caller function
 51+    if [[ -n "$1" ]]; then
 52+        _omz::log prompt "$1" "${${functrace[1]#_}%:*}"
 53+    fi
 54+
 55+    # Read one character
 56+    read -r -k 1
 57+
 58+    # If no newline entered, add a newline
 59+    if [[ "$REPLY" != $'\n' ]]; then
 60+        echo
 61+    fi
 62+}
 63+
 64 function _omz::log {
 65     # if promptsubst is set, a message with `` or $()
 66     # will be run even if quoted due to `print -P`
 67     setopt localoptions nopromptsubst
 68 
 69     # $1 = info|warn|error|debug
 70-    # $@ = text
 71+    # $2 = text
 72+    # $3 = (optional) name of the logger
 73 
 74     local logtype=$1
 75-    local logname=${${functrace[1]#_}%:*}
 76-    shift
 77+    local logname=${3:-${${functrace[1]#_}%:*}}
 78 
 79     # Don't print anything if debug is not active
 80     if [[ $logtype = debug && -z $_OMZ_DEBUG ]]; then
 81@@ -74,14 +102,52 @@ function _omz::log {
 82 
 83     # Choose coloring based on log type
 84     case "$logtype" in
 85-        prompt) print -Pn "%S%F{blue}$logname%f%s: $@" ;;
 86-        debug) print -P "%F{white}$logname%f: $@" ;;
 87-        info) print -P "%F{green}$logname%f: $@" ;;
 88-        warn) print -P "%S%F{yellow}$logname%f%s: $@" ;;
 89-        error) print -P "%S%F{red}$logname%f%s: $@" ;;
 90+        prompt) print -Pn "%S%F{blue}$logname%f%s: $2" ;;
 91+        debug) print -P "%F{white}$logname%f: $2" ;;
 92+        info) print -P "%F{green}$logname%f: $2" ;;
 93+        warn) print -P "%S%F{yellow}$logname%f%s: $2" ;;
 94+        error) print -P "%S%F{red}$logname%f%s: $2" ;;
 95     esac >&2
 96 }
 97 
 98+function _omz::plugin {
 99+    (( $# > 0 && $+functions[_omz::plugin::$1] )) || {
100+        cat <<EOF
101+Usage: omz plugin <command> [options]
102+
103+Available commands:
104+