Skip to content

Commit 3518434

Browse files
committed
- Improve generated code to support local completions
1 parent aa2fc51 commit 3518434

File tree

8 files changed

+39
-28
lines changed

8 files changed

+39
-28
lines changed

lib/completely/pattern.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def compgen
3030
@compgen ||= compgen!
3131
end
3232

33+
def text_without_prefix
34+
text.split(' ')[1..-1].join ' '
35+
end
36+
3337
private
3438

3539
def compgen!

lib/completely/template.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# Modifying it manually is not recommended
66
<%= function_name %>() {
77
local cur=${COMP_WORDS[COMP_CWORD]}
8+
local comp_line="${COMP_WORDS[*]:1}"
89

9-
case "$COMP_LINE" in
10+
case "$comp_line" in
1011
% patterns.each do |pattern|
1112
% next if pattern.empty?
12-
'<%= pattern.text %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;;
13+
'<%= pattern.text_without_prefix %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;;
1314
% end
1415
esac
1516
}

spec/approvals/cli/generated-script

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
# Modifying it manually is not recommended
66
_mygit_completions() {
77
local cur=${COMP_WORDS[COMP_CWORD]}
8+
local comp_line="${COMP_WORDS[*]:1}"
89

9-
case "$COMP_LINE" in
10-
'mygit status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;
11-
'mygit commit'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;
12-
'mygit init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;
13-
'mygit'*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;
10+
case "$comp_line" in
11+
'status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;
12+
'commit'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;
13+
'init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;
14+
''*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;
1415
esac
1516
}
1617

spec/approvals/cli/generated-script-alt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
# Modifying it manually is not recommended
66
_mycomps() {
77
local cur=${COMP_WORDS[COMP_CWORD]}
8+
local comp_line="${COMP_WORDS[*]:1}"
89

9-
case "$COMP_LINE" in
10-
'mygit status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;
11-
'mygit commit'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;
12-
'mygit init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;
13-
'mygit'*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;
10+
case "$comp_line" in
11+
'status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;
12+
'commit'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;
13+
'init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;
14+
''*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;
1415
esac
1516
}
1617

spec/approvals/cli/generated-wrapped-script

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ give_comps() {
66
echo $'# Modifying it manually is not recommended'
77
echo $'_mygit_completions() {'
88
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
9+
echo $' local comp_line="${COMP_WORDS[*]:1}"'
910
echo $''
10-
echo $' case "$COMP_LINE" in'
11-
echo $' \'mygit status\'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;'
12-
echo $' \'mygit commit\'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;'
13-
echo $' \'mygit init\'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;'
14-
echo $' \'mygit\'*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;'
11+
echo $' case "$comp_line" in'
12+
echo $' \'status\'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;'
13+
echo $' \'commit\'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;'
14+
echo $' \'init\'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;'
15+
echo $' \'\'*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;'
1516
echo $' esac'
1617
echo $'}'
1718
echo $''

spec/approvals/completions/function

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ send_completions() {
66
echo $'# Modifying it manually is not recommended'
77
echo $'_completely_completions() {'
88
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
9+
echo $' local comp_line="${COMP_WORDS[*]:1}"'
910
echo $''
10-
echo $' case "$COMP_LINE" in'
11-
echo $' \'completely generate\'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;;'
12-
echo $' \'completely init\'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;;'
13-
echo $' \'completely\'*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;;'
11+
echo $' case "$comp_line" in'
12+
echo $' \'generate\'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;;'
13+
echo $' \'init\'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;;'
14+
echo $' \'\'*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;;'
1415
echo $' esac'
1516
echo $'}'
1617
echo $''

spec/approvals/completions/script

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# Modifying it manually is not recommended
66
_completely_completions() {
77
local cur=${COMP_WORDS[COMP_CWORD]}
8+
local comp_line="${COMP_WORDS[*]:1}"
89

9-
case "$COMP_LINE" in
10-
'completely generate'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;;
11-
'completely init'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;;
12-
'completely'*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;;
10+
case "$comp_line" in
11+
'generate'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;;
12+
'init'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;;
13+
''*) COMPREPLY=($(compgen -W "--help --version init generate" -- "$cur")) ;;
1314
esac
1415
}
1516

spec/approvals/completions/script-only-spaces

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
# Modifying it manually is not recommended
66
_completely_completions() {
77
local cur=${COMP_WORDS[COMP_CWORD]}
8+
local comp_line="${COMP_WORDS[*]:1}"
89

9-
case "$COMP_LINE" in
10-
'completely generate'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;;
11-
'completely init'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;;
10+
case "$comp_line" in
11+
'generate'*) COMPREPLY=($(compgen -A directory -W "--help --force" -- "$cur")) ;;
12+
'init'*) COMPREPLY=($(compgen -W "--help" -- "$cur")) ;;
1213
esac
1314
}
1415

0 commit comments

Comments
 (0)