summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-01-27 13:12:21 -0500
committerBen Sima <ben@bsima.me>2021-01-27 13:12:21 -0500
commit9adac061d2916c0a07a26d25402a5b630542585c (patch)
treecf7f3afd711efac547bb2b354f4602ed3400ab2c
parent83efc28b170e31ad144970eeba38ced055eca97e (diff)
add fuzzy hledger add script
-rwxr-xr-xhledger-fadd54
1 files changed, 54 insertions, 0 deletions
diff --git a/hledger-fadd b/hledger-fadd
new file mode 100755
index 0000000..2ce276d
--- /dev/null
+++ b/hledger-fadd
@@ -0,0 +1,54 @@
+#!/usr/bin/env bash
+
+function fz {
+ readarray -t lines < <(fzf --expect alt-enter --print-query "$@")
+ query=${lines[0]}
+ enter=${lines[1]}
+ match=${lines[2]}
+ if [[ "$enter" == "alt-enter" ]]
+ then
+ echo "$query"
+ else
+ echo "$match"
+ fi
+}
+
+date=$(for n in $(seq 0 10); do date -d"$n days ago" "+%Y/%m/%d (%a)"; done | fz | awk '{ print $1 }')
+echo "date: $date"
+
+payee=$(hledger payees | fz --prompt="payee: ")
+echo "payee: $payee"
+
+# TODO: handle more than just 2 accounts
+to_account=$(hledger accounts | fz --prompt="to account: ")
+echo "to account: $to_account"
+read -rep "to amount: " to_amount
+
+
+from_account=$(hledger accounts | fz --prompt="from account: ")
+echo "from account: $from_account"
+read -rep "from amount: " from_amount
+
+
+read -r -d '' TX <<EOF
+$date $payee
+ $to_account $to_amount
+ $from_account $from_amount
+EOF
+
+tmp=$(mktemp)
+printf "\n%s\n" "$TX" >> "$tmp"
+cat "$tmp"
+
+read -rep "all good? y/e/n " ok
+case $ok in
+ y)
+ cat "$tmp" >> ~/org/fund/ledger.journal
+ ;;
+ e)
+ vim "$tmp" && cat "$tmp" >> ~/org/fund/ledger.journal
+ ;;
+ *)
+ exit 1
+ ;;
+esac