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 de2c095..9e86632 100644 --- a/lib/completely/template.erb +++ b/lib/completely/template.erb @@ -1,11 +1,14 @@ -#!/usr/bin/env bash +# <%= "#{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_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 % patterns.each do |pattern| @@ -13,6 +16,7 @@ '<%= pattern.text_without_prefix %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;; % end esac -} - +} && complete -F <%= function_name %> <%= command %> + +# ex: filetype=sh diff --git a/spec/approvals/cli/generated-script b/spec/approvals/cli/generated-script index 7628bbf..178f7fe 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 mygit + +# ex: filetype=sh diff --git a/spec/approvals/cli/generated-script-alt b/spec/approvals/cli/generated-script-alt index 40946d4..d789da7 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 mygit + +# ex: filetype=sh diff --git a/spec/approvals/cli/generated-wrapped-script b/spec/approvals/cli/generated-wrapped-script index 1dc1da2..304637d 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 $'} &&' 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 179cfa7..9c5ff03 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 $'} &&' 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 2f20403..b12dff4 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 completely + +# ex: filetype=sh diff --git a/spec/approvals/completions/script-only-spaces b/spec/approvals/completions/script-only-spaces index 7e03420..213bf5d 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 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