Skip to content

Commit 7e68b72

Browse files
potamidesakinomyoga
authored andcommitted
fix(_command_offset): handle exit 124 during meta-command completion
1 parent 2e9c762 commit 7e68b72

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

bash_completion

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,33 +2074,42 @@ _command_offset()
20742074
fi
20752075

20762076
if [[ -n $cspec ]]; then
2077-
if [[ ${cspec#* -F } != "$cspec" ]]; then
2078-
# complete -F <function>
2077+
for ((i = 0; i <= 1; i++)); do
2078+
if [[ ${cspec#* -F } != "$cspec" ]]; then
2079+
# complete -F <function>
20792080

2080-
# get function name
2081-
local func=${cspec#*-F }
2082-
func=${func%% *}
2081+
# get function name
2082+
local func=${cspec#*-F }
2083+
func=${func%% *}
20832084

2084-
if ((${#COMP_WORDS[@]} >= 2)); then
2085-
$func "$cmd" "${COMP_WORDS[-1]}" "${COMP_WORDS[-2]}"
2085+
if ((${#COMP_WORDS[@]} >= 2)); then
2086+
$func "$cmd" "${COMP_WORDS[-1]}" "${COMP_WORDS[-2]}"
2087+
else
2088+
$func "$cmd" "${COMP_WORDS[-1]}"
2089+
fi
2090+
2091+
# restart completion (once) if function exited with 124
2092+
if (($? == 124 && i == 0)); then
2093+
cspec=$(complete -p "$compcmd" 2>/dev/null)
2094+
[[ -n $cspec ]] && continue
2095+
fi
2096+
2097+
# restore initial compopts
2098+
local opt
2099+
while [[ $cspec == *" -o "* ]]; do
2100+
# FIXME: should we take "+o opt" into account?
2101+
cspec=${cspec#*-o }
2102+
opt=${cspec%% *}
2103+
compopt -o $opt
2104+
cspec=${cspec#"$opt"}
2105+
done
20862106
else
2087-
$func "$cmd" "${COMP_WORDS[-1]}"
2107+
cspec=${cspec#complete}
2108+
cspec=${cspec%%"$compcmd"}
2109+
COMPREPLY=($(eval compgen "$cspec" -- '$cur'))
20882110
fi
2089-
2090-
# restore initial compopts
2091-
local opt
2092-
while [[ $cspec == *" -o "* ]]; do
2093-
# FIXME: should we take "+o opt" into account?
2094-
cspec=${cspec#*-o }
2095-
opt=${cspec%% *}
2096-
compopt -o $opt
2097-
cspec=${cspec#"$opt"}
2098-
done
2099-
else
2100-
cspec=${cspec#complete}
2101-
cspec=${cspec%%"$compcmd"}
2102-
COMPREPLY=($(eval compgen "$cspec" -- '$cur'))
2103-
fi
2111+
break
2112+
done
21042113
elif ((${#COMPREPLY[@]} == 0)); then
21052114
# XXX will probably never happen as long as completion loader loads
21062115
# *something* for every command thrown at it ($cspec != empty)

0 commit comments

Comments
 (0)