From b195826c0fa0bb3911fd559406cac16cd31cd46a Mon Sep 17 00:00:00 2001 From: Vladimir Zhelezov Date: Fri, 11 Dec 2020 08:57:28 +0100 Subject: [PATCH] Revert "Refactor _hledger_compreply_optarg()" This reverts commit 2fd01d8ef51b897a63a2590556dbb3af7c13ffc9. Well, I was so wrong... --- shell-completion/hledger-completion.bash | 20 ++++++++++++++++---- shell-completion/hledger-completion.bash.m4 | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/shell-completion/hledger-completion.bash b/shell-completion/hledger-completion.bash index e5fa7e2a6..967a8aa59 100644 --- a/shell-completion/hledger-completion.bash +++ b/shell-completion/hledger-completion.bash @@ -188,12 +188,16 @@ _hledger_compgen() { # Try required option argument completion. Set COMPREPLY and return 0 on # success, 1 if option doesn't require an argument or out of context _hledger_compreply_optarg() { - local match wordlist + local optionIndex=${1:-$((cword - 1))} + local recursionLevel=${2:-0} + local wordlist + local error=0 + local match # Match the empty string on --file= [[ $cur == = ]] || match=$cur - case $prev in + case ${words[optionIndex]} in --alias) compopt -o nospace _hledger_compreply "$(_hledger_compgen "$(_hledger accounts --flat)" "" "$match")" @@ -234,12 +238,20 @@ _hledger_compreply_optarg() { -b|--begin|-e|--end|-p|--period|--depth|--drop) _hledger_compreply "" ;; + =) + # Recurse only once! + ((recursionLevel > 1)) && return 1 + if [[ ${words[optionIndex - 1]} == -* ]]; then + _hledger_compreply_optarg $((optionIndex - 1)) $((recursionLevel + 1)) + error=$? + fi + ;; *) - return 1 + error=1 ;; esac - return 0 + return $error } # Query filter completion through introspection diff --git a/shell-completion/hledger-completion.bash.m4 b/shell-completion/hledger-completion.bash.m4 index 00948ccc1..21b406e30 100644 --- a/shell-completion/hledger-completion.bash.m4 +++ b/shell-completion/hledger-completion.bash.m4 @@ -188,12 +188,16 @@ _hledger_compgen() { # Try required option argument completion. Set COMPREPLY and return 0 on # success, 1 if option doesn't require an argument or out of context _hledger_compreply_optarg() { - local match wordlist + local optionIndex=${1:-$((cword - 1))} + local recursionLevel=${2:-0} + local wordlist + local error=0 + local match # Match the empty string on --file= [[ $cur == = ]] || match=$cur - case $prev in + case ${words[optionIndex]} in --alias) compopt -o nospace _hledger_compreply "$(_hledger_compgen "$(_hledger accounts --flat)" "" "$match")" @@ -234,12 +238,20 @@ _hledger_compreply_optarg() { -b|--begin|-e|--end|-p|--period|--depth|--drop) _hledger_compreply "" ;; + =) + # Recurse only once! + ((recursionLevel > 1)) && return 1 + if [[ ${words[optionIndex - 1]} == -* ]]; then + _hledger_compreply_optarg $((optionIndex - 1)) $((recursionLevel + 1)) + error=$? + fi + ;; *) - return 1 + error=1 ;; esac - return 0 + return $error } # Query filter completion through introspection