From a9609c711bf7cc48a42c8d95c3e134f613702eed Mon Sep 17 00:00:00 2001 From: TruncatedDinosour <71613062+TruncatedDinosour@users.noreply.github.com> Date: Mon, 16 May 2022 17:44:40 +0000 Subject: [PATCH 1/3] Improve template --- lib/completely/template.erb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/completely/template.erb b/lib/completely/template.erb index de2c095..565a09b 100644 --- a/lib/completely/template.erb +++ b/lib/completely/template.erb @@ -1,9 +1,12 @@ -#!/usr/bin/env bash +# Bash completion script -*- shell-script -*- # This bash completions script was generated by # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended + <%= function_name %>() { + _init_completion -s || return + local cur=${COMP_WORDS[COMP_CWORD]} local comp_line="${COMP_WORDS[@]:1}" @@ -13,6 +16,6 @@ '<%= pattern.text_without_prefix %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;; % end esac -} +} && complete -F <%= function_name %> -o bashdefault -o default <%= command %> -complete -F <%= function_name %> <%= command %> +# ex: filetype=sh From 8172be29835be509c1803db3802ed475a8387666 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Mon, 16 May 2022 21:28:47 +0000 Subject: [PATCH 2/3] - Improve template --- lib/completely/completions.rb | 2 ++ lib/completely/template.erb | 11 ++++++----- spec/approvals/cli/generated-script | 14 +++++++++----- spec/approvals/cli/generated-script-alt | 14 +++++++++----- spec/approvals/cli/generated-wrapped-script | 14 +++++++++----- spec/approvals/completions/function | 14 +++++++++----- spec/approvals/completions/script | 14 +++++++++----- spec/approvals/completions/script-only-spaces | 14 +++++++++----- spec/spec_helper.rb | 1 + 9 files changed, 63 insertions(+), 35 deletions(-) diff --git a/lib/completely/completions.rb b/lib/completely/completions.rb index 90d1596..acb4435 100644 --- a/lib/completely/completions.rb +++ b/lib/completely/completions.rb @@ -10,7 +10,9 @@ def load(config_path, function_name: nil) begin data = YAML.load_file config_path, aliases: true rescue ArgumentError + # :nocov: data = YAML.load_file config_path + # :nocov: end new data, function_name: function_name diff --git a/lib/completely/template.erb b/lib/completely/template.erb index 565a09b..6206a8f 100644 --- a/lib/completely/template.erb +++ b/lib/completely/template.erb @@ -1,14 +1,14 @@ -# Bash completion script -*- shell-script -*- +# <%= "#{command} completion".ljust 56 %> -*- shell-script -*- # This bash completions script was generated by # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended <%= function_name %>() { + local cur comp_line _init_completion -s || return - - local cur=${COMP_WORDS[COMP_CWORD]} - local comp_line="${COMP_WORDS[@]:1}" + cur=${COMP_WORDS[COMP_CWORD]} + comp_line="${COMP_WORDS[@]:1}" case "$comp_line" in % patterns.each do |pattern| @@ -16,6 +16,7 @@ '<%= pattern.text_without_prefix %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;; % end esac -} && complete -F <%= function_name %> -o bashdefault -o default <%= command %> +} && +complete -F <%= function_name %> -o bashdefault -o default <%= command %> # ex: filetype=sh diff --git a/spec/approvals/cli/generated-script b/spec/approvals/cli/generated-script index 7628bbf..3505892 100644 --- a/spec/approvals/cli/generated-script +++ b/spec/approvals/cli/generated-script @@ -1,11 +1,14 @@ -#!/usr/bin/env bash +# mygit completion -*- shell-script -*- # This bash completions script was generated by # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended + _mygit_completions() { - local cur=${COMP_WORDS[COMP_CWORD]} - local comp_line="${COMP_WORDS[@]:1}" + local cur comp_line + _init_completion -s || return + cur=${COMP_WORDS[COMP_CWORD]} + comp_line="${COMP_WORDS[@]:1}" case "$comp_line" in 'status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;; @@ -13,6 +16,7 @@ _mygit_completions() { 'init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;; ''*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;; esac -} +} && +complete -F _mygit_completions -o bashdefault -o default mygit -complete -F _mygit_completions mygit +# ex: filetype=sh diff --git a/spec/approvals/cli/generated-script-alt b/spec/approvals/cli/generated-script-alt index 40946d4..7e43675 100644 --- a/spec/approvals/cli/generated-script-alt +++ b/spec/approvals/cli/generated-script-alt @@ -1,11 +1,14 @@ -#!/usr/bin/env bash +# mygit completion -*- shell-script -*- # This bash completions script was generated by # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended + _mycomps() { - local cur=${COMP_WORDS[COMP_CWORD]} - local comp_line="${COMP_WORDS[@]:1}" + local cur comp_line + _init_completion -s || return + cur=${COMP_WORDS[COMP_CWORD]} + comp_line="${COMP_WORDS[@]:1}" case "$comp_line" in 'status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;; @@ -13,6 +16,7 @@ _mycomps() { 'init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;; ''*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;; esac -} +} && +complete -F _mycomps -o bashdefault -o default mygit -complete -F _mycomps mygit +# ex: filetype=sh diff --git a/spec/approvals/cli/generated-wrapped-script b/spec/approvals/cli/generated-wrapped-script index 1dc1da2..dd9c868 100644 --- a/spec/approvals/cli/generated-wrapped-script +++ b/spec/approvals/cli/generated-wrapped-script @@ -1,12 +1,15 @@ give_comps() { - echo $'#!/usr/bin/env bash' + echo $'# mygit completion -*- shell-script -*-' echo $'' echo $'# This bash completions script was generated by' echo $'# completely (https://github.com/dannyben/completely)' echo $'# Modifying it manually is not recommended' + echo $'' echo $'_mygit_completions() {' - echo $' local cur=${COMP_WORDS[COMP_CWORD]}' - echo $' local comp_line="${COMP_WORDS[@]:1}"' + echo $' local cur comp_line' + echo $' _init_completion -s || return' + echo $' cur=${COMP_WORDS[COMP_CWORD]}' + echo $' comp_line="${COMP_WORDS[@]:1}"' echo $'' echo $' case "$comp_line" in' echo $' \'status\'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;' @@ -14,7 +17,8 @@ give_comps() { echo $' \'init\'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;' echo $' \'\'*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;' echo $' esac' - echo $'}' + echo $'} &&' + echo $'complete -F _mygit_completions -o bashdefault -o default mygit' echo $'' - echo $'complete -F _mygit_completions mygit' + echo $'# ex: filetype=sh' } \ No newline at end of file diff --git a/spec/approvals/completions/function b/spec/approvals/completions/function index 179cfa7..dd6f87e 100644 --- a/spec/approvals/completions/function +++ b/spec/approvals/completions/function @@ -1,19 +1,23 @@ send_completions() { - echo $'#!/usr/bin/env bash' + echo $'# completely completion -*- shell-script -*-' echo $'' echo $'# This bash completions script was generated by' echo $'# completely (https://github.com/dannyben/completely)' echo $'# Modifying it manually is not recommended' + echo $'' echo $'_completely_completions() {' - echo $' local cur=${COMP_WORDS[COMP_CWORD]}' - echo $' local comp_line="${COMP_WORDS[@]:1}"' + echo $' local cur comp_line' + echo $' _init_completion -s || return' + echo $' cur=${COMP_WORDS[COMP_CWORD]}' + echo $' comp_line="${COMP_WORDS[@]:1}"' echo $'' echo $' case "$comp_line" in' echo $' \'generate\'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;;' echo $' \'init\'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;;' echo $' \'\'*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;;' echo $' esac' - echo $'}' + echo $'} &&' + echo $'complete -F _completely_completions -o bashdefault -o default completely' echo $'' - echo $'complete -F _completely_completions completely' + echo $'# ex: filetype=sh' } \ No newline at end of file diff --git a/spec/approvals/completions/script b/spec/approvals/completions/script index 2f20403..e9a348e 100644 --- a/spec/approvals/completions/script +++ b/spec/approvals/completions/script @@ -1,17 +1,21 @@ -#!/usr/bin/env bash +# completely completion -*- shell-script -*- # This bash completions script was generated by # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended + _completely_completions() { - local cur=${COMP_WORDS[COMP_CWORD]} - local comp_line="${COMP_WORDS[@]:1}" + local cur comp_line + _init_completion -s || return + cur=${COMP_WORDS[COMP_CWORD]} + comp_line="${COMP_WORDS[@]:1}" case "$comp_line" in 'generate'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;; 'init'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; ''*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;; esac -} +} && +complete -F _completely_completions -o bashdefault -o default completely -complete -F _completely_completions completely +# ex: filetype=sh diff --git a/spec/approvals/completions/script-only-spaces b/spec/approvals/completions/script-only-spaces index 7e03420..a9abf82 100644 --- a/spec/approvals/completions/script-only-spaces +++ b/spec/approvals/completions/script-only-spaces @@ -1,16 +1,20 @@ -#!/usr/bin/env bash +# completely completion -*- shell-script -*- # This bash completions script was generated by # completely (https://github.com/dannyben/completely) # Modifying it manually is not recommended + _completely_completions() { - local cur=${COMP_WORDS[COMP_CWORD]} - local comp_line="${COMP_WORDS[@]:1}" + local cur comp_line + _init_completion -s || return + cur=${COMP_WORDS[COMP_CWORD]} + comp_line="${COMP_WORDS[@]:1}" case "$comp_line" in 'generate'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;; 'init'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; esac -} +} && +complete -F _completely_completions -o bashdefault -o default completely -complete -F _completely_completions completely +# ex: filetype=sh diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9900152..d85ca9e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,6 +25,7 @@ def run_completions(fixture:, compline:, cword:) File.write "spec/tmp/test.sh", <<~BASH #{subject.script} + source /usr/share/bash-completion/bash_completion COMP_WORDS=( #{compline} ) COMP_CWORD=#{cword} _testme From cf2f5c28c620ae698376f2476454dda683765e52 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Tue, 17 May 2022 05:35:40 +0000 Subject: [PATCH 3/3] remove -o bashdefault -o default --- lib/completely/template.erb | 2 +- spec/approvals/cli/generated-script | 2 +- spec/approvals/cli/generated-script-alt | 2 +- spec/approvals/cli/generated-wrapped-script | 2 +- spec/approvals/completions/function | 2 +- spec/approvals/completions/script | 2 +- spec/approvals/completions/script-only-spaces | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/completely/template.erb b/lib/completely/template.erb index 6206a8f..9e86632 100644 --- a/lib/completely/template.erb +++ b/lib/completely/template.erb @@ -17,6 +17,6 @@ % end esac } && -complete -F <%= function_name %> -o bashdefault -o default <%= command %> +complete -F <%= function_name %> <%= command %> # ex: filetype=sh diff --git a/spec/approvals/cli/generated-script b/spec/approvals/cli/generated-script index 3505892..178f7fe 100644 --- a/spec/approvals/cli/generated-script +++ b/spec/approvals/cli/generated-script @@ -17,6 +17,6 @@ _mygit_completions() { ''*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;; esac } && -complete -F _mygit_completions -o bashdefault -o default mygit +complete -F _mygit_completions mygit # ex: filetype=sh diff --git a/spec/approvals/cli/generated-script-alt b/spec/approvals/cli/generated-script-alt index 7e43675..d789da7 100644 --- a/spec/approvals/cli/generated-script-alt +++ b/spec/approvals/cli/generated-script-alt @@ -17,6 +17,6 @@ _mycomps() { ''*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;; esac } && -complete -F _mycomps -o bashdefault -o default mygit +complete -F _mycomps mygit # ex: filetype=sh diff --git a/spec/approvals/cli/generated-wrapped-script b/spec/approvals/cli/generated-wrapped-script index dd9c868..304637d 100644 --- a/spec/approvals/cli/generated-wrapped-script +++ b/spec/approvals/cli/generated-wrapped-script @@ -18,7 +18,7 @@ give_comps() { echo $' \'\'*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;' echo $' esac' echo $'} &&' - echo $'complete -F _mygit_completions -o bashdefault -o default mygit' + echo $'complete -F _mygit_completions mygit' echo $'' echo $'# ex: filetype=sh' } \ No newline at end of file diff --git a/spec/approvals/completions/function b/spec/approvals/completions/function index dd6f87e..9c5ff03 100644 --- a/spec/approvals/completions/function +++ b/spec/approvals/completions/function @@ -17,7 +17,7 @@ send_completions() { echo $' \'\'*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;;' echo $' esac' echo $'} &&' - echo $'complete -F _completely_completions -o bashdefault -o default completely' + echo $'complete -F _completely_completions completely' echo $'' echo $'# ex: filetype=sh' } \ No newline at end of file diff --git a/spec/approvals/completions/script b/spec/approvals/completions/script index e9a348e..b12dff4 100644 --- a/spec/approvals/completions/script +++ b/spec/approvals/completions/script @@ -16,6 +16,6 @@ _completely_completions() { ''*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;; esac } && -complete -F _completely_completions -o bashdefault -o default completely +complete -F _completely_completions completely # ex: filetype=sh diff --git a/spec/approvals/completions/script-only-spaces b/spec/approvals/completions/script-only-spaces index a9abf82..213bf5d 100644 --- a/spec/approvals/completions/script-only-spaces +++ b/spec/approvals/completions/script-only-spaces @@ -15,6 +15,6 @@ _completely_completions() { 'init'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; esac } && -complete -F _completely_completions -o bashdefault -o default completely +complete -F _completely_completions completely # ex: filetype=sh