From c139bb24a7053ba863a7d7960ed9a91c2d6e8b36 Mon Sep 17 00:00:00 2001 From: Vladimir Zhelezov Date: Fri, 11 Dec 2020 09:53:16 +0100 Subject: [PATCH] Minor refactor of main function No functional changes except special treatment of `help` subcommand --- shell-completion/hledger-completion.bash | 24 +++++++++++---------- shell-completion/hledger-completion.bash.m4 | 24 +++++++++++---------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/shell-completion/hledger-completion.bash b/shell-completion/hledger-completion.bash index 967a8aa59..9b0080a70 100644 --- a/shell-completion/hledger-completion.bash +++ b/shell-completion/hledger-completion.bash @@ -65,19 +65,21 @@ _hledger_completion_function() { # Avoid setting compopt bellow if completing an option [[ $cur == -* ]] && return - # Almost all subcommands accept [QUERY] - # -> always add accounts to completion list - # Except for those few that will complain - local noQuery=(files help test) - # shellcheck disable=2076 - [[ " ${noQuery[*]} " =~ " $subcommand " ]] && return - # Add any other subcommand special treatment here, or if it becomes unwieldy - # move it out in say _hledger_compreply_subcommand() and return on success. - - # Query specific completions + # Query completion _hledger_compreply_query && return - # Do not sort, keep accounts and query filters grouped separately + # Subcommand specific + case $subcommand in + files|test) return 0 ;; + help) + compopt -o nosort +o filenames + _hledger_compreply_append "$(compgen -W "$(hledger help | tail -n 1)" -- "$cur")" + return 0 + ;; + esac + + # Offer query filters and accounts for the rest + # Do not sort. Keep options, accounts and query filters grouped separately compopt -o nosort -o nospace _hledger_compreply_append "$(_hledger_compgen "$_hledger_complist_query_filters")" if [[ -z $cur ]]; then diff --git a/shell-completion/hledger-completion.bash.m4 b/shell-completion/hledger-completion.bash.m4 index 21b406e30..8b7ae9e43 100644 --- a/shell-completion/hledger-completion.bash.m4 +++ b/shell-completion/hledger-completion.bash.m4 @@ -65,19 +65,21 @@ _hledger_completion_function() { # Avoid setting compopt bellow if completing an option [[ $cur == -* ]] && return - # Almost all subcommands accept [QUERY] - # -> always add accounts to completion list - # Except for those few that will complain - local noQuery=(files help test) - # shellcheck disable=2076 - [[ " ${noQuery[*]} " =~ " $subcommand " ]] && return - # Add any other subcommand special treatment here, or if it becomes unwieldy - # move it out in say _hledger_compreply_subcommand() and return on success. - - # Query specific completions + # Query completion _hledger_compreply_query && return - # Do not sort, keep accounts and query filters grouped separately + # Subcommand specific + case $subcommand in + files|test) return 0 ;; + help) + compopt -o nosort +o filenames + _hledger_compreply_append "$(compgen -W "$(hledger help | tail -n 1)" -- "$cur")" + return 0 + ;; + esac + + # Offer query filters and accounts for the rest + # Do not sort. Keep options, accounts and query filters grouped separately compopt -o nosort -o nospace _hledger_compreply_append "$(_hledger_compgen "$_hledger_complist_query_filters")" if [[ -z $cur ]]; then