From 046421e712635e793a4057e1461c1083de5ee7cd Mon Sep 17 00:00:00 2001 From: Vladimir Zhelezov Date: Sun, 13 Dec 2020 07:43:29 +0100 Subject: [PATCH] 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. --- shell-completion/hledger-completion.bash | 12 +++--------- shell-completion/hledger-completion.bash.m4 | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/shell-completion/hledger-completion.bash b/shell-completion/hledger-completion.bash index f53e385de..0b8ecd48c 100644 --- a/shell-completion/hledger-completion.bash +++ b/shell-completion/hledger-completion.bash @@ -36,15 +36,9 @@ _hledger_completion_function() { # $subcommand == bal --> balance, balancesheet, balancesheetequity, etc. # Do not ignore them! if ((i == cword)); then - local subcommandMatches - subcommandMatches=$(grep -c "^$subcommand" <<< "$_hledger_complist_commands") - if ((subcommandMatches > 1)); then - subcommand= - break - else - _hledger_compreply "$subcommand" - return 0 - fi + compopt +o filenames + _hledger_compreply "$(_hledger_compgen "$_hledger_complist_commands")" + return 0 fi break done diff --git a/shell-completion/hledger-completion.bash.m4 b/shell-completion/hledger-completion.bash.m4 index 2c30c8cf9..9bfc23a32 100644 --- a/shell-completion/hledger-completion.bash.m4 +++ b/shell-completion/hledger-completion.bash.m4 @@ -36,15 +36,9 @@ _hledger_completion_function() { # $subcommand == bal --> balance, balancesheet, balancesheetequity, etc. # Do not ignore them! if ((i == cword)); then - local subcommandMatches - subcommandMatches=$(grep -c "^$subcommand" <<< "$_hledger_complist_commands") - if ((subcommandMatches > 1)); then - subcommand= - break - else - _hledger_compreply "$subcommand" - return 0 - fi + compopt +o filenames + _hledger_compreply "$(_hledger_compgen "$_hledger_complist_commands")" + return 0 fi break done