blob: 3e9b9be191a46fdb8a99b9159d7c57c32dd36d18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/usr/bin/env bash
function fz {
readarray -t lines < <(fzf --height 50% --reverse --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 14); 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=$(cat <(hledger accounts payee:"$payee") <(hledger accounts) | fz --prompt="to account: ")
echo "to account: $to_account"
read -rep "to amount: " to_amount
from_account=$(cat <(hledger accounts payee:"$payee") <(hledger accounts) | fz --prompt="from account: ")
echo "from account: $from_account"
read -rep "from amount: " -i "-$to_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
n)
exit 1
;;
e)
vim "$tmp" && cat "$tmp" >> ~/org/fund/ledger.journal
;;
*)
cat "$tmp" >> ~/org/fund/ledger.journal
;;
esac
|