script to copy a previous transaction to today

This commit is contained in:
Felix Van der Jeugt 2019-04-18 17:11:30 +02:00
parent f93db6c456
commit 10ba047854
No known key found for this signature in database
GPG Key ID: 58B209295023754D

30
local/bin/ladd Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
ledger="${1:-$LEDGER_FILE}"
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
?^\$?
+s/....-..-../$(date +'%Y-%m-%d')/
# delete empty lines at end and quit
/^\$/,\$d
wq
HERE
vis +\$ "$ledger"
clear