Skip to content

Commit 63ab6b0

Browse files
committed
add some guards to the completions template
1 parent 0029c4e commit 63ab6b0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/completely/templates/template.erb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
local result=()
1111

1212
# words the user already typed (excluding the command itself)
13-
local used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
13+
local used=()
14+
if ((COMP_CWORD > 1)); then
15+
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
16+
fi
1417

1518
if [[ "${cur:0:1}" == "-" ]]; then
1619
# Completing an option: offer everything (including options)
@@ -38,9 +41,14 @@
3841

3942
<%= function_name %>() {
4043
local cur=${COMP_WORDS[COMP_CWORD]}
41-
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
44+
local compwords=()
45+
if ((COMP_CWORD > 0)); then
46+
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
47+
fi
4248
local compline="${compwords[*]}"
4349

50+
COMPREPLY=()
51+
4452
% if ENV['COMPLETELY_DEBUG']
4553
if [[ -n "$COMPLETELY_DEBUG" ]]; then
4654
echo "compline: '$compline'" > 'completely-debug.txt'

0 commit comments

Comments
 (0)