diff options
author | axel <axel@liljencrantz.se> | 2006-01-31 02:51:50 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2006-01-31 02:51:50 +1000 |
commit | 521d09b6d0264aaac17b9359ebcb1a0cb6ca8906 (patch) | |
tree | 7297a413ff9a5d020c1691e7727e3b22a0bc8175 /init | |
parent | 3efb0bf5cf7b799b8df039e4fa3dd593248dc415 (diff) |
Add support for calculating completions for arbitrary commands through the 'complete' builtin
darcs-hash:20060130165150-ac50b-5e2ef3bb0298dd5e1a5d6fbdade314cc73ef36f3.gz
Diffstat (limited to 'init')
-rw-r--r-- | init/completions/complete.fish | 1 | ||||
-rw-r--r-- | init/completions/sudo.fish | 4 | ||||
-rw-r--r-- | init/completions/time.fish | 2 | ||||
-rw-r--r-- | init/fish_complete.fish.in | 39 |
4 files changed, 41 insertions, 5 deletions
diff --git a/init/completions/complete.fish b/init/completions/complete.fish index 55d4994e..2dcc8200 100644 --- a/init/completions/complete.fish +++ b/init/completions/complete.fish @@ -11,3 +11,4 @@ complete -c complete -s d -l description -d (_ "Description of this completions" complete -c complete -s u -l unauthorative -d (_ "Option list is not complete") complete -c complete -s e -l erase -d (_ "Remove completion") complete -c complete -s h -l help -d (_ "Display help and exit") +complete -c complete -s C -l do-complete -d (_ "Print all completions for the specified commandline") diff --git a/init/completions/sudo.fish b/init/completions/sudo.fish index 6eb7fafc..c4ac1397 100644 --- a/init/completions/sudo.fish +++ b/init/completions/sudo.fish @@ -1,10 +1,8 @@ # # Completion for sudo # -# Generate a list of commands -# -complete -c sudo -d (_ "Command to run") -x -a "(__fish_complete_command)" +complete -c sudo -d (_ "Command to run") -x -a "(__fish_complete_subcommand)" complete -c sudo -s h -d (_ "Display help and exit") complete -c sudo -s v -d (_ "Validate") diff --git a/init/completions/time.fish b/init/completions/time.fish index 77721b6b..5abe2d46 100644 --- a/init/completions/time.fish +++ b/init/completions/time.fish @@ -1,5 +1,5 @@ -complete -c time -a "(__fish_complete_command)" -d (_ "Command") +complete -c time -a "(__fish_complete_subcommand -- -o --output -f --format)" -d (_ "Command") complete -c time -s f -l format -d (_ "Specify output format") -x complete -c time -s p -l portable -d (_ "Use the portable output format") diff --git a/init/fish_complete.fish.in b/init/fish_complete.fish.in index 83674bca..1b5ae1de 100644 --- a/init/fish_complete.fish.in +++ b/init/fish_complete.fish.in @@ -96,9 +96,46 @@ function __fish_complete_pids -d "Print a list of process identifiers along with end function __fish_complete_command -d "Complete using all available commands" - for i in $PATH; command ls $i; end + printf "%s\n" (commandline -ct)(complete -C (commandline -ct)) end +function __fish_complete_subcommand -d "Complete subcommand" + set -l res "" + set -l had_cmd 0 + set -l cmd (commandline -cop) (commandline -ct) + set -l skip_next 1 + + for i in $cmd + + if test "$skip_next" = 1 + set skip_next 0 + continue + end + + if test "$had_cmd" = 1 + set res "$res $i" + else + + if contains $i $argv + set skip_next 1 + continue + end + + switch $i + case '-*' + + case '*' + set had_cmd 1 + set res $i + end + end + end + + printf "%s\n" (commandline -ct)(complete -C $res) + +end + + function __fish_print_hostnames -d "Print a list of known hostnames" |