Skip to content

Commit

Permalink
config(bash): add wp-cli bash completions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsneighbour committed Sep 5, 2024
1 parent 32aab14 commit b54ea9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions bash/_completions/wp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# bash completion for the `wp` command

_wp_complete() {
local OLD_IFS="$IFS"
local cur=${COMP_WORDS[COMP_CWORD]}

IFS=$'\n'; # want to preserve spaces at the end
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

IFS="$OLD_IFS"
return 0
}
complete -o nospace -F _wp_complete wp
2 changes: 1 addition & 1 deletion bash/completions
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SSH_COMPLETE=("$(cut -f1 -d' ' ~/.ssh/known_hosts |\
grep -e '[[:alpha:]]')")
complete -o default -W "${SSH_COMPLETE[*]}" ssh

for FILE in "${DOTFILES_PATH}"/bash/_completions/{hugo,netlify,npm,robo}; do
for FILE in "${DOTFILES_PATH}"/bash/_completions/{hugo,netlify,npm,robo,wp}; do
# this routine ranges through a folder of files that we don't explicitly know (@davidsneighbour)
# see https://github.com/koalaman/shellcheck/wiki/SC1090
# shellcheck source-path=SOURCEDIR/completions
Expand Down

0 comments on commit b54ea9e

Please sign in to comment.