Revert "Refactor _hledger_compreply_optarg()"

This reverts commit 2fd01d8ef51b897a63a2590556dbb3af7c13ffc9.

Well, I was so wrong...
This commit is contained in:
Vladimir Zhelezov 2020-12-11 08:57:28 +01:00
parent d30913c6a8
commit b195826c0f
2 changed files with 32 additions and 8 deletions

View File

@ -188,12 +188,16 @@ _hledger_compgen() {
# Try required option argument completion. Set COMPREPLY and return 0 on # Try required option argument completion. Set COMPREPLY and return 0 on
# success, 1 if option doesn't require an argument or out of context # success, 1 if option doesn't require an argument or out of context
_hledger_compreply_optarg() { _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=<TAB> # Match the empty string on --file=<TAB>
[[ $cur == = ]] || match=$cur [[ $cur == = ]] || match=$cur
case $prev in case ${words[optionIndex]} in
--alias) --alias)
compopt -o nospace compopt -o nospace
_hledger_compreply "$(_hledger_compgen "$(_hledger accounts --flat)" "" "$match")" _hledger_compreply "$(_hledger_compgen "$(_hledger accounts --flat)" "" "$match")"
@ -234,12 +238,20 @@ _hledger_compreply_optarg() {
-b|--begin|-e|--end|-p|--period|--depth|--drop) -b|--begin|-e|--end|-p|--period|--depth|--drop)
_hledger_compreply "" _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 esac
return 0 return $error
} }
# Query filter completion through introspection # Query filter completion through introspection

View File

@ -188,12 +188,16 @@ _hledger_compgen() {
# Try required option argument completion. Set COMPREPLY and return 0 on # Try required option argument completion. Set COMPREPLY and return 0 on
# success, 1 if option doesn't require an argument or out of context # success, 1 if option doesn't require an argument or out of context
_hledger_compreply_optarg() { _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=<TAB> # Match the empty string on --file=<TAB>
[[ $cur == = ]] || match=$cur [[ $cur == = ]] || match=$cur
case $prev in case ${words[optionIndex]} in
--alias) --alias)
compopt -o nospace compopt -o nospace
_hledger_compreply "$(_hledger_compgen "$(_hledger accounts --flat)" "" "$match")" _hledger_compreply "$(_hledger_compgen "$(_hledger accounts --flat)" "" "$match")"
@ -234,12 +238,20 @@ _hledger_compreply_optarg() {
-b|--begin|-e|--end|-p|--period|--depth|--drop) -b|--begin|-e|--end|-p|--period|--depth|--drop)
_hledger_compreply "" _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 esac
return 0 return $error
} }
# Query filter completion through introspection # Query filter completion through introspection