From 8deccc2e9b8a774e539409339297a0a0d9e508a1 Mon Sep 17 00:00:00 2001 From: tanishiking Date: Wed, 5 Dec 2018 21:25:01 +0900 Subject: [PATCH] Add test autocompletion for fish https://github.com/scalacenter/bloop/issues/426 --- etc/fish/bloop.fish | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/etc/fish/bloop.fish b/etc/fish/bloop.fish index b130dc98ae..55726a274b 100644 --- a/etc/fish/bloop.fish +++ b/etc/fish/bloop.fish @@ -57,6 +57,23 @@ function __fish_seen_subcommand_from_project_commands __fish_seen_subcommand_from $prj end +# https://github.com/fish-shell/fish-shell/blob/04795eb8ea63e9b68bc85342aae81b9a60cd09c8/share/functions/__fish_prev_arg_in.fish +function __fish_prev_arg_in + set -l tokens (commandline -co) + set -l tokenCount (count $tokens) + if test $tokenCount -lt 2 + # need at least cmd and prev argument + return 1 + end + for arg in $argv + if string match -q -- $tokens[-1] $argv[0] + return 0 + end + end + + return 1 +end + function _flags_for_command -a cmd bloop autocomplete --format fish --mode flags --command $cmd end @@ -82,6 +99,8 @@ complete -c bloop -f -n "__assert_args_count 0" -a '(_commands)' # Only a project command has been provided complete -c bloop -f -n "__assert_args_count 1; and __fish_seen_subcommand_from_project_commands" -a '(_projects)' +# Only a project command has been provided +complete -c bloop -x -n "__fish_seen_subcommand_from test; and not __fish_prev_arg_in --only" -a '(_testsfqcn)' for cmd in (_commands) set -l minTokens (_is_project_command $cmd) @@ -98,4 +117,4 @@ for cmd in (_commands) _bloop_cmpl_ $minTokens $cmd -l $parsed[1] end end -end \ No newline at end of file +end