2019-04-18 17:11:30 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
ledger="${1:-$LEDGER_FILE}"
|
|
|
|
|
2019-11-16 19:27:53 +01:00
|
|
|
# fuzzy select a transaction title
|
2019-04-18 17:11:30 +02:00
|
|
|
selection="$(sed -n 's/....-..-..\( [*!]\)\? //p' "$ledger" | sort | uniq | fzf)"
|
|
|
|
[ -z "$selection" ] && clear && exit 0 # quit if escaped
|
|
|
|
|
|
|
|
cat <<HERE | ed --silent "$ledger"
|
|
|
|
# append a newline for easier searching
|
|
|
|
\$a
|
|
|
|
|
|
|
|
.
|
|
|
|
# yank matching transaction (closed by empty line)
|
|
|
|
?^....-..-..\( [*!]\)\? ${selection}\$?;/^\$/y
|
|
|
|
# select line below last none-empty line
|
|
|
|
$
|
|
|
|
?^..*?
|
|
|
|
+
|
|
|
|
# put transaction
|
|
|
|
x
|
|
|
|
# replace date with today
|
|
|
|
?^\$?
|
2019-05-10 15:07:45 +02:00
|
|
|
+s/....-..-..\( [*!]\)\?/$(date +'%Y-%m-%d')/
|
2019-04-18 17:11:30 +02:00
|
|
|
# delete empty lines at end and quit
|
|
|
|
/^\$/,\$d
|
|
|
|
wq
|
|
|
|
HERE
|
|
|
|
|
2019-11-16 19:27:53 +01:00
|
|
|
# review change: open end of the file in vis
|
2019-04-18 17:11:30 +02:00
|
|
|
vis +\$ "$ledger"
|
2019-11-16 19:27:53 +01:00
|
|
|
|
2019-04-18 17:11:30 +02:00
|
|
|
clear
|