From 04316d379dde01bd4f6849853097f674c2ebcc12 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Tue, 6 Jun 2017 18:46:27 +0100 Subject: [PATCH] fish/fzf: Complete subcommands (sudo, env) --- .config/fish/fzf.fish | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.config/fish/fzf.fish b/.config/fish/fzf.fish index 7c3afb25..ff470c65 100644 --- a/.config/fish/fzf.fish +++ b/.config/fish/fzf.fish @@ -33,7 +33,25 @@ bind m fzf-select ## - ~/ ## - echo \$HOME-$H function fzf-complete -d 'fzf completion and print selection back to commandline' - set -l complist (complete -C(commandline -c)) + # As of 2.6, fish's "complete" function does not understand + # subcommands. Instead, we use the same hack as __fish_complete_subcommand and + # extract the subcommand manually. + set -l cmd (commandline -co) (commandline -ct) + switch $cmd[1] + case env sudo + for i in (seq 2 (count $cmd)) + switch $cmd[$i] + case '-*' + case '*=*' + case '*' + set cmd $cmd[$i..-1] + break + end + end + end + set cmd (string join -- ' ' $cmd) + + set -l complist (complete -C$cmd) set -l result string join -- \n $complist | sort | eval (__fzfcmd) -m --select-1 --exit-0 --header '(commandline)' | cut -f1 | while read -l r; set result $result $r; end