configuration/local/bin/ladd
Felix Van der Jeugt 2d11d55ed4
explain some steps
2019-11-16 19:27:53 +01:00

34 lines
671 B
Bash
Executable File

#!/bin/sh
ledger="${1:-$LEDGER_FILE}"
# fuzzy select a transaction title
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
# review change: open end of the file in vis
vis +\$ "$ledger"
clear