Last active
May 22, 2020 11:58
-
-
Save samy/fea739e64fb373101fd8c76f249d234e to your computer and use it in GitHub Desktop.
Shell auto-completion script for themes and plugins list for wp-cli subcommands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_wp_complete() { | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local command=${COMP_WORDS[1]} | |
local subcommand=${COMP_WORDS[2]} | |
COMPREPLY="" | |
if [[ "$command" = "plugin" ]] | |
then | |
case "$subcommand" in | |
activate|deactivate|update|delete|get|is-active|path|status|uninstall|verify-checksums) | |
local plugin_list=$(wp plugin list --field=name --format=csv) | |
COMPREPLY=( $(compgen -W "${plugin_list}" -- ${cur} )) | |
;; | |
*) | |
esac | |
fi | |
if [[ "$COMPREPLY" = "" ]] | |
then | |
local opts="$(wp cli completions --line="$COMP_LINE" --point="$COMP_POINT")" | |
if [[ "$opts" =~ \<file\>\s* ]] | |
then | |
COMPREPLY=( $(compgen -f -- $cur) ) | |
elif [[ $opts = "" ]] | |
then | |
COMPREPLY=( $(compgen -f -- $cur) ) | |
else | |
COMPREPLY=( ${opts[*]} ) | |
fi | |
fi | |
return 0 | |
} | |
complete -o nospace -F _wp_complete wp |
with theme
_wp_complete() {
local cur=${COMP_WORDS[COMP_CWORD]}
local command=${COMP_WORDS[1]}
local subcommand=${COMP_WORDS[2]}
COMPREPLY=""
if [[ "$command" = "plugin" ]]
then
case "$subcommand" in
activate|deactivate|update|delete|get|is-active|path|status|uninstall|verify-checksums)
local plugin_list=$(wp plugin list --field=name --format=csv)
COMPREPLY=( $(compgen -W "${plugin_list}" -- ${cur} ))
;;
*)
esac
elif [[ "$command" = "theme" ]]
then
case "$subcommand" in
activate|delete|disable|enable|is-active|is-installed|path|status|update)
local theme_list=$(wp theme list --field=name --format=csv)
COMPREPLY=( $(compgen -W "${theme_list}" -- ${cur} ))
;;
*)
esac
fi
if [[ "$COMPREPLY" = "" ]]
then
local opts="$(wp cli completions --line="$COMP_LINE" --point="$COMP_POINT")"
if [[ "$opts" =~ \<file\>\s* ]]
then
COMPREPLY=( $(compgen -f -- $cur) )
elif [[ $opts = "" ]]
then
COMPREPLY=( $(compgen -f -- $cur) )
else
COMPREPLY=( ${opts[*]} )
fi
fi
return 0
}
complete -o nospace -F _wp_complete wp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
all plugin subcommands: wp plugin...
activate|deactivate|update|delete|get|is-active|path|status|uninstall|verify-checksums