Skip to content

Instantly share code, notes, and snippets.

@peterjaffray
Last active July 15, 2026 18:00
Show Gist options
  • Select an option

  • Save peterjaffray/0f2bdc0b297a87d5aada90e62816e11d to your computer and use it in GitHub Desktop.

Select an option

Save peterjaffray/0f2bdc0b297a87d5aada90e62816e11d to your computer and use it in GitHub Desktop.
wp-cli completions for fish cli //~/.config/fish/completions/wp.fish
wp-cli completions for fish cli //~/.config/fish/completions/wp.fish
function __wp_complete
set -l old_ifs $IFS
set -l cur (commandline -ct)
set IFS \n
set -l opts (wp cli completions --line=(commandline) --point=(commandline -C))
if string match -q --regex -- "\<file\>\s*" $opts
return (commandline -f)
else if test -z "$opts"
return (commandline -f)
else
for opt in $opts
printf '%s\n' $opt
end
end
set IFS $old_ifs
end
complete -c wp -f -a "(__wp_complete)"
@astratagem

Copy link
Copy Markdown

This fails to properly complete command options. Here's the output when I try to complete wp @staging user list -- (cursor is at end of that string, after --):

$ wp @staging user list string match: --role=: unknown option                            

~/.config/fish/completions/wp.fish (line 10):
    if string match -q --regex "\<file\>\s*" $opts
       ^
in function '__wp_complete'
        called on line 1 of file /nix/store/42ikxb2i4hccrw7kvi9vg1py3m26mxs7-source/functions/_autopair_tab.fish
in command substitution
        called on line 6 of file /nix/store/42ikxb2i4hccrw7kvi9vg1py3m26mxs7-source/functions/_autopair_tab.fish
in function '_autopair_tab'

(Type 'help string' for related documentation)
wpwp @staging user list --help                                                           
--color     --field=   --network    --quiet           --skip-plugins=  --user=
--context=  --fields=  --no-color   --require=        --skip-themes=
--debug=    --format=  --path=      --role=           --ssh=
--exec=     --http=    --prompt=    --skip-packages   --url= 

@peterjaffray

Copy link
Copy Markdown
Author

The bug is on line 10: string match chokes on $opts values like --role= because they look like option flags to string match itself. Let me fix it properly... one sec. Thank you for the comment!!@

@peterjaffray

Copy link
Copy Markdown
Author

Good catch, thanks. The completion helper was passing wp-cli's ---prefixed option tokens (--role=, --url=, etc.) straight into string match, which parsed them as its own flags and aborted. Added a -- separator before the arguments (string match -q --regex -- "\<file\>\s*" $opts) and pushed the fix to the gist. Should complete cleanly now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment