Skip to content

Commit ca3d1e8

Browse files
authored
Merge pull request #81 from yassun7010/fix_bash
Fix: bash completion.
2 parents e7f7de2 + f65db7e commit ca3d1e8

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

cmdcomp/v2/templates/bash.sh.jinja

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{%- macro argument_completion(argument) -%}
66
{% if argument.type == "select" -%}
77
if [ $cur -eq $COMP_CWORD ] ; then
8-
COMPREPLY=( $(compgen -W "{{ argument.options|join(" ") }}" -- "$cur") )
8+
COMPREPLY=( $(compgen -W "{{ argument.options|join(" ") }}" -- "${COMP_WORDS[COMP_CWORD]}") )
99

1010
return 0
1111
else
@@ -21,7 +21,7 @@ else
2121
fi
2222
{%- elif argument.type == "command" -%}
2323
if [ $cur -eq $COMP_CWORD ] ; then
24-
COMPREPLY=( $(compgen -W "{{ argument.execute }}" -- "$cur") )
24+
COMPREPLY=( $(compgen -W "$({{ argument.execute }})" -- "${COMP_WORDS[COMP_CWORD]}") )
2525

2626
return 0
2727
else
@@ -94,11 +94,11 @@ cur=$COMP_CWORD
9494
{#- macro def -#}
9595
{%- macro file_completion(base_path) -%}
9696
_get_comp_words_by_ref -n : cur prev cword
97-
dir="$(echo ${cur} | grep -o ".*/")"
97+
dir="$(echo ${COMP_WORDS[COMP_CWORD]} | grep -o ".*/")"
9898
if test "${dir}" ;then
99-
COMPREPLY=( $(compgen -W "$(ls -F "{{ base_path }}/${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${cur}") )
99+
COMPREPLY=( $(compgen -W "$(ls -F "{{ base_path }}/${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${COMP_WORDS[COMP_CWORD]}") )
100100
else
101-
COMPREPLY=( $(compgen -W "$(ls -F "{{ base_path }}/")" -- "${cur}") )
101+
COMPREPLY=( $(compgen -W "$(ls -F "{{ base_path }}/")" -- "${COMP_WORDS[COMP_CWORD]}") )
102102
fi
103103
{%- endmacro -%}
104104

examples/v2/output.bash

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ _cliname() {
8787
--config)
8888
if [ $cur -eq $COMP_CWORD ] ; then
8989
_get_comp_words_by_ref -n : cur prev cword
90-
dir="$(echo ${cur} | grep -o ".*/")"
90+
dir="$(echo ${COMP_WORDS[COMP_CWORD]} | grep -o ".*/")"
9191
if test "${dir}" ;then
92-
COMPREPLY=( $(compgen -W "$(ls -F "./${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${cur}") )
92+
COMPREPLY=( $(compgen -W "$(ls -F "./${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${COMP_WORDS[COMP_CWORD]}") )
9393
else
94-
COMPREPLY=( $(compgen -W "$(ls -F "./")" -- "${cur}") )
94+
COMPREPLY=( $(compgen -W "$(ls -F "./")" -- "${COMP_WORDS[COMP_CWORD]}") )
9595
fi
9696

9797
return 0
@@ -102,7 +102,7 @@ _cliname() {
102102

103103
--type)
104104
if [ $cur -eq $COMP_CWORD ] ; then
105-
COMPREPLY=( $(compgen -W "json toml" -- "$cur") )
105+
COMPREPLY=( $(compgen -W "json toml" -- "${COMP_WORDS[COMP_CWORD]}") )
106106

107107
return 0
108108
else
@@ -156,11 +156,11 @@ _cliname() {
156156
cur=$COMP_CWORD
157157
if [ $cur -eq $COMP_CWORD ] ; then
158158
_get_comp_words_by_ref -n : cur prev cword
159-
dir="$(echo ${cur} | grep -o ".*/")"
159+
dir="$(echo ${COMP_WORDS[COMP_CWORD]} | grep -o ".*/")"
160160
if test "${dir}" ;then
161-
COMPREPLY=( $(compgen -W "$(ls -F "./${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${cur}") )
161+
COMPREPLY=( $(compgen -W "$(ls -F "./${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${COMP_WORDS[COMP_CWORD]}") )
162162
else
163-
COMPREPLY=( $(compgen -W "$(ls -F "./")" -- "${cur}") )
163+
COMPREPLY=( $(compgen -W "$(ls -F "./")" -- "${COMP_WORDS[COMP_CWORD]}") )
164164
fi
165165

166166
return 0
@@ -191,11 +191,11 @@ _cliname() {
191191
1)
192192
if [ $cur -eq $COMP_CWORD ] ; then
193193
_get_comp_words_by_ref -n : cur prev cword
194-
dir="$(echo ${cur} | grep -o ".*/")"
194+
dir="$(echo ${COMP_WORDS[COMP_CWORD]} | grep -o ".*/")"
195195
if test "${dir}" ;then
196-
COMPREPLY=( $(compgen -W "$(ls -F "$HOME/${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${cur}") )
196+
COMPREPLY=( $(compgen -W "$(ls -F "$HOME/${dir}" | sed -E "s@(.*)@${dir}\1@g")" -- "${COMP_WORDS[COMP_CWORD]}") )
197197
else
198-
COMPREPLY=( $(compgen -W "$(ls -F "$HOME/")" -- "${cur}") )
198+
COMPREPLY=( $(compgen -W "$(ls -F "$HOME/")" -- "${COMP_WORDS[COMP_CWORD]}") )
199199
fi
200200

201201
return 0
@@ -256,7 +256,7 @@ _cliname() {
256256
fi
257257
cur=$COMP_CWORD
258258
if [ $cur -eq $COMP_CWORD ] ; then
259-
COMPREPLY=( $(compgen -W "echo 'script1.sh script2.sh script3.sh'" -- "$cur") )
259+
COMPREPLY=( $(compgen -W "$(echo 'script1.sh script2.sh script3.sh')" -- "${COMP_WORDS[COMP_CWORD]}") )
260260

261261
return 0
262262
else

0 commit comments

Comments
 (0)