From c15d70571c27b6f6ac1377261972d948a39f5b47 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 3 Sep 2022 14:39:22 +0000 Subject: [PATCH 1/3] - Hide flag completion unless input ends with a hyphen --- lib/completely/completions.rb | 6 ++++- lib/completely/pattern.rb | 7 ++--- lib/completely/templates/template.erb | 18 +++++++++++++ spec/approvals/cli/generated-script | 26 ++++++++++++++++--- spec/approvals/cli/generated-script-alt | 26 ++++++++++++++++--- spec/approvals/cli/generated-wrapped-script | 26 ++++++++++++++++--- spec/approvals/cli/test/completely-tester.sh | 26 ++++++++++++++++--- spec/approvals/completions/function | 24 ++++++++++++++--- spec/approvals/completions/script | 24 ++++++++++++++--- spec/approvals/completions/script-only-spaces | 22 ++++++++++++++-- spec/approvals/completions/script-with-debug | 18 +++++++++++++ spec/completely/integration.yml | 20 +++++++++----- spec/completely/pattern_spec.rb | 7 ++--- spec/completely/zsh_spec.rb | 4 +-- spec/fixtures/tester/default.bash | 26 ++++++++++++++++--- 15 files changed, 237 insertions(+), 43 deletions(-) diff --git a/lib/completely/completions.rb b/lib/completely/completions.rb index a36484a..bf7e87d 100644 --- a/lib/completely/completions.rb +++ b/lib/completely/completions.rb @@ -54,7 +54,7 @@ def tester def patterns! config.map do |text, completions| - Pattern.new text, completions + Pattern.new text, completions, pattern_function_name end.sort_by { |pattern| -pattern.length } end @@ -74,6 +74,10 @@ def function_name @function_name ||= "_#{command}_completions" end + def pattern_function_name + @pattern_function_name ||= "#{function_name}_filter" + end + def pattern_prefixes patterns.map &:prefix end diff --git a/lib/completely/pattern.rb b/lib/completely/pattern.rb index 01a2f7d..41b22bf 100644 --- a/lib/completely/pattern.rb +++ b/lib/completely/pattern.rb @@ -1,10 +1,11 @@ module Completely class Pattern - attr_reader :text, :completions + attr_reader :text, :completions, :function_name - def initialize(text, completions) + def initialize(text, completions, function_name) @text = text @completions = completions || [] + @function_name = function_name end def length @@ -53,7 +54,7 @@ def compgen def compgen! result = [] result << %Q[#{actions.join ' '}] if actions.any? - result << %Q[-W "#{words.join ' '}"] if words.any? + result << %Q[-W "$(#{function_name} "#{words.join ' '}")"] if words.any? result.any? ? result.join(' ') : nil end end diff --git a/lib/completely/templates/template.erb b/lib/completely/templates/template.erb index 1c134c5..4f93952 100644 --- a/lib/completely/templates/template.erb +++ b/lib/completely/templates/template.erb @@ -4,6 +4,24 @@ # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +<%= function_name %>_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + <%= function_name %>() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") diff --git a/spec/approvals/cli/generated-script b/spec/approvals/cli/generated-script index 6a96aa4..24cdc0d 100644 --- a/spec/approvals/cli/generated-script +++ b/spec/approvals/cli/generated-script @@ -4,6 +4,24 @@ # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +_mygit_completions_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + _mygit_completions() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") @@ -11,19 +29,19 @@ _mygit_completions() { case "$compline" in 'status'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" ) ;; 'commit'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" ) ;; 'init'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "--bare" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" ) ;; *) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --version status init commit" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" ) ;; esac diff --git a/spec/approvals/cli/generated-script-alt b/spec/approvals/cli/generated-script-alt index 5836055..dd7d6a2 100644 --- a/spec/approvals/cli/generated-script-alt +++ b/spec/approvals/cli/generated-script-alt @@ -4,6 +4,24 @@ # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +_mycomps_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + _mycomps() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") @@ -11,19 +29,19 @@ _mycomps() { case "$compline" in 'status'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mycomps_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" ) ;; 'commit'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mycomps_filter "--help --message --all -a --quiet -q")" -- "$cur" ) ;; 'init'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "--bare" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mycomps_filter "--bare")" -- "$cur" ) ;; *) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --version status init commit" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mycomps_filter "--help --version status init commit")" -- "$cur" ) ;; esac diff --git a/spec/approvals/cli/generated-wrapped-script b/spec/approvals/cli/generated-wrapped-script index f9a72fd..df2a660 100644 --- a/spec/approvals/cli/generated-wrapped-script +++ b/spec/approvals/cli/generated-wrapped-script @@ -5,6 +5,24 @@ give_comps() { echo $'# completely (https://github.com/dannyben/completely)' echo $'# Modifying it manually is not recommended' echo $'' + echo $'_mygit_completions_filter() {' + echo $' local words="$1"' + echo $' local cur=${COMP_WORDS[COMP_CWORD]}' + echo $' local result=()' + echo $'' + echo $' if [[ "${cur:0:1}" == "-" ]]; then' + echo $' echo "$words"' + echo $' ' + echo $' else' + echo $' for word in $words; do' + echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")' + echo $' done' + echo $'' + echo $' echo "${result[*]}"' + echo $'' + echo $' fi' + echo $'}' + echo $'' echo $'_mygit_completions() {' echo $' local cur=${COMP_WORDS[COMP_CWORD]}' echo $' local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")' @@ -12,19 +30,19 @@ give_comps() { echo $'' echo $' case "$compline" in' echo $' \'status\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" )' echo $' ;;' echo $'' echo $' \'commit\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" )' echo $' ;;' echo $'' echo $' \'init\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "--bare" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" )' echo $' ;;' echo $'' echo $' *)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --version status init commit" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" )' echo $' ;;' echo $'' echo $' esac' diff --git a/spec/approvals/cli/test/completely-tester.sh b/spec/approvals/cli/test/completely-tester.sh index 1281700..f4d2be3 100644 --- a/spec/approvals/cli/test/completely-tester.sh +++ b/spec/approvals/cli/test/completely-tester.sh @@ -12,6 +12,24 @@ fi # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +_mygit_completions_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + _mygit_completions() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") @@ -19,19 +37,19 @@ _mygit_completions() { case "$compline" in 'status'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" ) ;; 'commit'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" ) ;; 'init'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "--bare" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" ) ;; *) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --version status init commit" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" ) ;; esac diff --git a/spec/approvals/completions/function b/spec/approvals/completions/function index 08230d9..8cea3cc 100644 --- a/spec/approvals/completions/function +++ b/spec/approvals/completions/function @@ -5,6 +5,24 @@ send_completions() { echo $'# completely (https://github.com/dannyben/completely)' echo $'# Modifying it manually is not recommended' echo $'' + echo $'_completely_completions_filter() {' + echo $' local words="$1"' + echo $' local cur=${COMP_WORDS[COMP_CWORD]}' + echo $' local result=()' + echo $'' + echo $' if [[ "${cur:0:1}" == "-" ]]; then' + echo $' echo "$words"' + echo $' ' + echo $' else' + echo $' for word in $words; do' + echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")' + echo $' done' + echo $'' + echo $' echo "${result[*]}"' + echo $'' + echo $' fi' + echo $'}' + echo $'' echo $'_completely_completions() {' echo $' local cur=${COMP_WORDS[COMP_CWORD]}' echo $' local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")' @@ -12,15 +30,15 @@ send_completions() { echo $'' echo $' case "$compline" in' echo $' \'generate\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "--help --force" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur" )' echo $' ;;' echo $'' echo $' \'init\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help")" -- "$cur" )' echo $' ;;' echo $'' echo $' *)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --version init generate" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help --version init generate")" -- "$cur" )' echo $' ;;' echo $'' echo $' esac' diff --git a/spec/approvals/completions/script b/spec/approvals/completions/script index 7714257..108f28b 100644 --- a/spec/approvals/completions/script +++ b/spec/approvals/completions/script @@ -4,6 +4,24 @@ # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +_completely_completions_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + _completely_completions() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") @@ -11,15 +29,15 @@ _completely_completions() { case "$compline" in 'generate'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "--help --force" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur" ) ;; 'init'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help")" -- "$cur" ) ;; *) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --version init generate" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help --version init generate")" -- "$cur" ) ;; esac diff --git a/spec/approvals/completions/script-only-spaces b/spec/approvals/completions/script-only-spaces index 90a94f9..b25939e 100644 --- a/spec/approvals/completions/script-only-spaces +++ b/spec/approvals/completions/script-only-spaces @@ -4,6 +4,24 @@ # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +_completely_completions_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + _completely_completions() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") @@ -11,11 +29,11 @@ _completely_completions() { case "$compline" in 'generate'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "--help --force" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur" ) ;; 'init'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help")" -- "$cur" ) ;; esac diff --git a/spec/approvals/completions/script-with-debug b/spec/approvals/completions/script-with-debug index 99149f3..4240173 100644 --- a/spec/approvals/completions/script-with-debug +++ b/spec/approvals/completions/script-with-debug @@ -4,6 +4,24 @@ # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +_completely_completions_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + _completely_completions() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") diff --git a/spec/completely/integration.yml b/spec/completely/integration.yml index 95d3de6..dd46568 100644 --- a/spec/completely/integration.yml +++ b/spec/completely/integration.yml @@ -1,24 +1,29 @@ ftp: - compline: "ftp " - expected: [--help, --version, download, list, upload] + expected: [download, list, upload] + +- compline: "ftp -" + expected: [--help, --version] - compline: "ftp downl" expected: [download] - compline: "ftp download " expected: [--help, --override, another-dir, dummy-dir, ftp.yaml, gradual.yaml] - expected: [--help, --override, another-dir, dir with spaces, dummy-dir, file with spaces.txt, ftp.yaml, gradual.yaml] - compline: "ftp upload " - expected: [--confirm, --help, another-dir, dir with spaces, dummy-dir] + expected: [another-dir, dir with spaces, dummy-dir] + +- compline: "ftp upload -" + expected: [--confirm, --help] -- compline: "ftp connect ssh " +- compline: "ftp connect ssh -" expected: [--keyfile] - compline: "ftp connect --protocol " expected: [scp, sftp] -- compline: "/anything/goes/ftp list " +- compline: "/anything/goes/ftp list -" expected: [--help, --short] gradual: @@ -35,7 +40,10 @@ gradual: expected: [subcommand] - compline: "cli command subcommand " - expected: [--color, --force, -c, help] + expected: [help] + +- compline: "cli command subcommand -" + expected: [--color, --force, -c] - compline: "cli command subcommand --" expected: [--color, --force] diff --git a/spec/completely/pattern_spec.rb b/spec/completely/pattern_spec.rb index 15d4ace..e2bed5c 100644 --- a/spec/completely/pattern_spec.rb +++ b/spec/completely/pattern_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' describe Pattern do - subject { described_class.new text, completions } + subject { described_class.new text, completions, function_name } let(:text) { "git commit" } let(:completions) { %w[--message --help ] } + let(:function_name) { "_filter" } describe '#length' do it "returns the string length of the pattern text" do @@ -73,7 +74,7 @@ describe '#compgen' do it "returns a line of compgen arguments" do - expect(subject.compgen).to eq %q[-A file -A user -W "--message --help"] + expect(subject.compgen).to eq %q[-A file -A user -W "$(_filter "--message --help")"] end context "when there are no words for -W" do @@ -88,7 +89,7 @@ let(:completions) { %w[--message --help] } it "omits the -A arguments" do - expect(subject.compgen).to eq %q[-W "--message --help"] + expect(subject.compgen).to eq %q[-W "$(_filter "--message --help")"] end end diff --git a/spec/completely/zsh_spec.rb b/spec/completely/zsh_spec.rb index 5464303..2cf3e66 100644 --- a/spec/completely/zsh_spec.rb +++ b/spec/completely/zsh_spec.rb @@ -20,14 +20,14 @@ describe "completions script and test script" do it "returns completions without erroring" do - expect(subject).to eq "somedir\n--help\n--force" + expect(subject).to eq "somedir" end context "on bash" do let(:shell) { 'bash' } it "returns the same output" do - expect(subject).to eq "somedir\n--help\n--force" + expect(subject).to eq "somedir" end end end diff --git a/spec/fixtures/tester/default.bash b/spec/fixtures/tester/default.bash index b212310..6d03977 100644 --- a/spec/fixtures/tester/default.bash +++ b/spec/fixtures/tester/default.bash @@ -4,6 +4,24 @@ # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended +_cli_completions_filter() { + local words="$1" + local cur=${COMP_WORDS[COMP_CWORD]} + local result=() + + if [[ "${cur:0:1}" == "-" ]]; then + echo "$words" + + else + for word in $words; do + [[ "${word:0:1}" != "-" ]] && result+=("$word") + done + + echo "${result[*]}" + + fi +} + _cli_completions() { local cur=${COMP_WORDS[COMP_CWORD]} local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}") @@ -11,19 +29,19 @@ _cli_completions() { case "$compline" in 'command childcommand'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--quiet --verbose -q -v" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--quiet --verbose -q -v")" -- "$cur" ) ;; 'command subcommand'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--force --quiet" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--force --quiet")" -- "$cur" ) ;; 'command'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "subcommand childcommand" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "subcommand childcommand")" -- "$cur" ) ;; *) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "--help --version command conquer" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --version command conquer")" -- "$cur" ) ;; esac From 94f767be3cb8e401068ba90ab8655051ec5403b3 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 3 Sep 2022 14:42:57 +0000 Subject: [PATCH 2/3] fix specs --- spec/completely/integration.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/completely/integration.yml b/spec/completely/integration.yml index dd46568..fc5e96e 100644 --- a/spec/completely/integration.yml +++ b/spec/completely/integration.yml @@ -9,7 +9,10 @@ ftp: expected: [download] - compline: "ftp download " - expected: [--help, --override, another-dir, dummy-dir, ftp.yaml, gradual.yaml] + expected: [another-dir, dir with spaces, dummy-dir, file with spaces.txt, ftp.yaml, gradual.yaml] + +- compline: "ftp download -" + expected: [--help, --override] - compline: "ftp upload " expected: [another-dir, dir with spaces, dummy-dir] From 649110663c60296392c3926f877709b365f3a96f Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 3 Sep 2022 14:58:42 +0000 Subject: [PATCH 3/3] mention the new behavior in the readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c834123..e257f85 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,9 @@ Each pattern in this configuration file will be checked against the user's input, and if the input **starts with** a matching pattern, the list that follows it will be suggested as completions. +Note that the suggested completions will not show flags (string that start with +a hyphen `-`) unless the input ends with a hyphen. + To generate the bash script, simply run: ```bash