Skip to content

Commit f7db3c1

Browse files
authored
Merge pull request #5954 from aldisruiz/add/fish-completion
Add fish shell completion
2 parents f701f40 + 0656485 commit f7db3c1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

utils/wp.fish

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Fish completion for the `wp` command
2+
# Check $fish_complete_path for possible install locations
3+
# Or check the documentation:
4+
# https://fishshell.com/docs/current/completions.html#where-to-put-completions
5+
6+
function __wp_cli_complete
7+
# Get current buffer and cursor
8+
set --local COMP_LINE (commandline)
9+
set --local COMP_POINT (commandline -C)
10+
11+
# Get valid completions from wp-cli
12+
set --local opts (wp cli completions --line=$COMP_LINE --point=$COMP_POINT)
13+
14+
# wp-cli will indicate if it needs a file
15+
if string match -qe "<file> " -- $opts
16+
command ls -1
17+
else
18+
# Remove unnecessary double spaces that wp-cli splits options with
19+
string trim -- $opts
20+
# `string` echoes each result on a newline.
21+
# Which is then collected for use with the `-a` flag for `complete`.
22+
end
23+
end
24+
complete -f -a "(__wp_cli_complete)" wp

0 commit comments

Comments
 (0)