general cleanup

This commit is contained in:
Felix Van der Jeugt 2024-07-24 08:35:41 +02:00
parent ffced8fca4
commit 3ffb35cc2e
No known key found for this signature in database
GPG key ID: 58B209295023754D
25 changed files with 149 additions and 120 deletions

View file

@ -11,7 +11,8 @@ to the current date. Finally, it opens the end of the file in $EDITOR.
Bonus over 'hledger add': interactive matching it easier, and
transaction formatting is retained because it's just a copy.
add_file The transaction is appended to this file.
add_file The transaction is appended to this file. Using -
will output the transaction to stdout instead.
Default (if set): \$LEDGER_ADD_FILE
Default (otherwise): \$LEDGER_FILE
@ -37,18 +38,24 @@ done
shift $((OPTIND - 1))
# fuzzy select a transaction title
selection="$(sed -n 's/....-..-..\( [*!]\)\? //p' "${@:-$LEDGER_FILE}" | sort | uniq | sk)"
selection="$(sed -n 's/....-..-..\( [*!]\)\? //p' "${@:-$LEDGER_FILE}" | sort | uniq | sk | sed 's_/_\\/_g')"
[ -z "$selection" ] && exit 0 # quit if escaped
sed -n "/....-..-..\( [*!]\)\? ${selection}\$/,/^\$/p" "${@:-$LEDGER_FILE}" | # print matching transactions
sed '${/^$/d}' | # remove trailing empty line
sed -n '/^$/{s/.*//;x;d};H;${x;p}' | # remove all before the last empty line
sed "s/^....-..-..\( [*!]\)\?/$(date +'%Y-%m-%d')/" | # replace date with today, remove marker
sponge -a "$add_file" # append to the file, use sponge in case it's also an input file
if [ "$add_file" = '-' ]; then
cat
else
sponge -a "$add_file" # append to the file, use sponge in case it's also an input file
fi
# review change: open end of the file (if I know how)
case "$EDITOR" in
vi*|nvi*) "$EDITOR" +\$ "$add_file" ;;
emacs) "$EDITOR" "$add_file" -f end-of-buffer ;;
*) "$EDITOR" "$add_file" ;;
esac
if [ "$add_file" != '-' ]; then
case "$EDITOR" in
vi*|nvi*) "$EDITOR" +\$ "$add_file" ;;
emacs) "$EDITOR" "$add_file" -f end-of-buffer ;;
*) "$EDITOR" "$add_file" ;;
esac
fi