4455c13e063cf81ba427f98e1dce2024ecd50762
- Author
- pollyduan <pollyduan@163.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/lib/cli.zsh b/lib/cli.zsh
2index 7e3e37be8ba39030583db468c1d0f82f7ce32963..1289df7309d2682a491d98461b308b50d3fbcac3 100644
3--- a/lib/cli.zsh
4+++ b/lib/cli.zsh
5@@ -37,7 +37,13 @@ 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=('info:Get plugin information' 'list:List plugins' 'load:Load plugin(s)')
10+ plugin) subcmds=(
11+ 'disable:Disable plugin(s)'
12+ 'enable:Enable plugin(s)'
13+ 'info:Get plugin information'
14+ 'list:List plugins'
15+ 'load:Load plugin(s)'
16+ )
17 _describe 'command' subcmds ;;
18 pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches')
19 _describe 'command' subcmds ;;
20@@ -45,8 +51,21 @@ function _omz {
21 _describe 'command' subcmds ;;
22 esac
23 elif (( CURRENT == 4 )); then
24- case "$words[2]::$words[3]" in
25- plugin::(info|load))
26+ case "${words[2]}::${words[3]}" in
27+ plugin::(disable|enable|load))
28+ local -aU valid_plugins
29+
30+ if [[ "${words[3]}" = disable ]]; then
31+ # if command is "disable", only offer already enabled plugins
32+ valid_plugins=($plugins)
33+ else
34+ valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
35+ # if command is "enable", remove already enabled plugins
36+ [[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
37+ fi
38+
39+ _describe 'plugin' valid_plugins ;;
40+ plugin::info)
41 local -aU plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
42 _describe 'plugin' plugins ;;
43 theme::use)
44@@ -54,18 +73,27 @@ function _omz {
45 _describe 'theme' themes ;;
46 esac
47 elif (( CURRENT > 4 )); then
48- case "$words[2]::$words[3]" in
49- plugin::load)
50- local -aU plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
51+ case "${words[2]}::${words[3]}" in
52+ plugin::(enable|disable|load))
53+ local -aU valid_plugins
54+
55+ if [[ "${words[3]}" = disable ]]; then
56+ # if command is "disable", only offer already enabled plugins
57+ valid_plugins=($plugins)
58+ else
59+ valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
60+ # if command is "enable", remove already enabled plugins
61+ [[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
62+ fi
63
64 # Remove plugins already passed as arguments
65 # NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which
66 # has a space after them. This is to avoid removing plugins partially passed, which makes
67 # the completion not add a space after the completed plugin.
68 local -a args=(${words[4,$(( CURRENT - 1))]})
69- plugins=(${plugins:|args})
70+ valid_plugins=(${valid_plugins:|args})
71
72- _describe 'plugin' plugins ;;
73+ _describe 'plugin' valid_plugins ;;
74 esac
75 fi
76
77@@ -161,9 +189,11 @@ Usage: omz plugin <command> [options]
78
79 Available commands:
80
81- info <plugin> Get information of a plugin
82- list List all available Oh My Zsh plugins
83- load <plugin> Load plugin(s)
84+ disable <plugin> Disable plugin(s)
85+ enable <plugin> Enable plugin(s)
86+ info <plugin> Get information of a plugin
87+ list List all available Oh My Zsh plugins
88+ load <plugin> Load plugin(s)
89
90 EOF
91 return 1
92@@ -175,6 +205,172 @@ EOF
93 _omz::plugin::$command "$@"
94 }
95
96+function _omz::plugin::disable {
97+ if [[ -z "$1" ]]; then
98+ echo >&2 "Usage: omz plugin disable <plugin> [...]"
99+ return 1
100+ fi
101+
102+ # Check that plugin is in $plugins
103+ local -a dis_plugins=()
104+ for plugin in "$@"; do