Simplify sub-command loop logic

If the cursor is on the sub-command, just offer sub-command
completions and be done with it. It was way over complicated.
This commit is contained in:
Vladimir Zhelezov 2020-12-13 07:43:29 +01:00
parent f5d2a6bcc3
commit 046421e712
2 changed files with 6 additions and 18 deletions

View File

@ -36,15 +36,9 @@ _hledger_completion_function() {
# $subcommand == bal --> balance, balancesheet, balancesheetequity, etc. # $subcommand == bal --> balance, balancesheet, balancesheetequity, etc.
# Do not ignore them! # Do not ignore them!
if ((i == cword)); then if ((i == cword)); then
local subcommandMatches compopt +o filenames
subcommandMatches=$(grep -c "^$subcommand" <<< "$_hledger_complist_commands") _hledger_compreply "$(_hledger_compgen "$_hledger_complist_commands")"
if ((subcommandMatches > 1)); then return 0
subcommand=
break
else
_hledger_compreply "$subcommand"
return 0
fi
fi fi
break break
done done

View File

@ -36,15 +36,9 @@ _hledger_completion_function() {
# $subcommand == bal --> balance, balancesheet, balancesheetequity, etc. # $subcommand == bal --> balance, balancesheet, balancesheetequity, etc.
# Do not ignore them! # Do not ignore them!
if ((i == cword)); then if ((i == cword)); then
local subcommandMatches compopt +o filenames
subcommandMatches=$(grep -c "^$subcommand" <<< "$_hledger_complist_commands") _hledger_compreply "$(_hledger_compgen "$_hledger_complist_commands")"
if ((subcommandMatches > 1)); then return 0
subcommand=
break
else
_hledger_compreply "$subcommand"
return 0
fi
fi fi
break break
done done