Skip to content

Instantly share code, notes, and snippets.

@lrtrln
Last active May 22, 2020 16:16
Show Gist options
  • Save lrtrln/6c34253360441f895abdac31edf30c1d to your computer and use it in GitHub Desktop.
Save lrtrln/6c34253360441f895abdac31edf30c1d to your computer and use it in GitHub Desktop.
Shell auto-completion script for themes and plugins list for wp-cli subcommands
_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)
COMPREPLY=( $(cd $(wp plugin path); compgen -d -- "${cur}" ) )
;;
*)
esac
elif [[ "$command" = "theme" ]]
then
case "$subcommand" in
activate|delete|disable|enable|is-active|is-installed|path|status|update)
COMPREPLY=( $(cd $(wp theme path); compgen -d -- "${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