9e5f280f87f2c127896c20edcdd8cd023b5b1893

Author
Fernando Crespo <fernando82@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(CLI): add `plugin info` subcommand (#9452)

Co-authored-by: Fernando Crespo <fxcrespo@iMac-44054.local>
Co-authored-by: Marc Cornellà <marc.cornella@live.com>

Diff

 1diff --git a/lib/cli.zsh b/lib/cli.zsh
 2index 6fcffdf878b37eaaef279e912b8031fe92837447..86a0ed3c47415ca2432b859cd744d4e5a5a45d01 100644
 3--- a/lib/cli.zsh
 4+++ b/lib/cli.zsh
 5@@ -37,7 +37,7 @@ function _omz {
 6       changelog) local -a refs
 7         refs=("${(@f)$(command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
 8         _describe 'command' refs ;;
 9-      plugin) subcmds=('list:List plugins')
10+      plugin) subcmds=('info:Get plugin information' 'list:List plugins')
11         _describe 'command' subcmds ;;
12       pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches')
13         _describe 'command' subcmds ;;
14@@ -46,6 +46,8 @@ function _omz {
15     esac
16   elif (( CURRENT == 4 )); then
17     case "$words[2]::$words[3]" in
18+      plugin::info) compadd "$ZSH"/plugins/*/README.md(.N:h:t) \
19+        "$ZSH_CUSTOM"/plugins/*/README.md(.N:h:t) ;;
20       theme::use) compadd "$ZSH"/themes/*.zsh-theme(.N:t:r) \
21         "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::) ;;
22     esac
23@@ -143,6 +145,7 @@ Usage: omz plugin <command> [options]
24 
25 Available commands:
26 
27+  info <plugin>   Get information of a plugin
28   list            List all available Oh My Zsh plugins
29 
30 EOF
31@@ -155,6 +158,29 @@ EOF
32   _omz::plugin::$command "$@"
33 }
34 
35+function _omz::plugin::info {
36+  if [[ -z "$1" ]]; then
37+    echo >&2 "Usage: omz plugin info <plugin>"
38+    return 1
39+  fi
40+
41+  local readme
42+  for readme in "$ZSH_CUSTOM/plugins/$1/README.md" "$ZSH/plugins/$1/README.md"; do
43+    if [[ -f "$readme" ]]; then
44+      (( ${+commands[less]} )) && less "$readme" || cat "$readme"
45+      return 0
46+    fi
47+  done
48+
49+  if [[ -d "$ZSH_CUSTOM/plugins/$1" || -d "$ZSH/plugins/$1" ]]; then
50+    _omz::log error "the '$1' plugin doesn't have a README file"
51+  else
52+    _omz::log error "'$1' plugin not found"
53+  fi
54+
55+  return 1
56+}
57+
58 function _omz::plugin::list {
59   local -a custom_plugins builtin_plugins
60   custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t))