From 58ed1f020d62c53723e4e64b5232e9127bcd8598 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 2 Sep 2022 09:58:13 -0400 Subject: hledger fadd improvements --- hledger-fadd | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/hledger-fadd b/hledger-fadd index b4b7034..be713e4 100755 --- a/hledger-fadd +++ b/hledger-fadd @@ -1,7 +1,10 @@ #!/usr/bin/env bash function fz { - readarray -t lines < <(fzf --height 50% --reverse --expect alt-enter --print-query "$@") + readarray -t lines < <(fzf \ + --height 50% --reverse --expect alt-enter --print-query "$@" \ + --bind "pgup:preview-page-up" --bind "pgdn:preview-page-down" + ) query=${lines[0]} enter=${lines[1]} match=${lines[2]} @@ -13,32 +16,43 @@ function fz { fi } -date=$(for n in $(seq 0 14); do date -d"$n days ago" "+%Y/%m/%d (%a)"; done \ +# cache accounts for speed +accounts=$(mktemp) +hledger accounts > $accounts & + +date=$(for n in $(seq 0 31); do date -d"$n days ago" "+%Y/%m/%d (%a)"; done \ | fzf --height 50% --reverse --delimiter '/' \ --preview="gcal -H yes %{1}{2}{3}" \ --preview-window 'noborder,top,8' \ - --header-first --header "Today is $(date '+%Y/%m/%d (%a)')" + --header-first --header "Today is $(date '+%Y/%m/%d (%a)')" \ + | cut -d ' ' -f1 ) echo "date: $date" -payee=$(hledger payees | fz --prompt="payee: ") +payee=$(hledger payees | fz --prompt="payee: " --preview='hledger print payee:{..}') echo "payee: $payee" -# TODO: handle more than just 2 accounts -to_account=$(cat <(hledger accounts payee:"$payee") <(hledger accounts) | fz --prompt="to account: ") -echo "to account: $to_account" +# store past txs in a file, in the background, so I don't have to wait for the +# command to re-run each time +past_txs=$(mktemp) +hledger print payee:"$payee" > $past_txs & + read -rep "to amount: " to_amount +to_account=$(cat $accounts \ + | fz --prompt="to account: " --preview="cat $past_txs") +echo "to account: $to_account" -from_account=$(cat <(hledger accounts payee:"$payee") <(hledger accounts) | fz --prompt="from account: ") +from_account=$(cat $accounts \ + | fz --prompt="from account: " --preview="cat $past_txs") echo "from account: $from_account" read -rep "from amount: " -i "-$to_amount" from_amount read -r -d '' TX <