configuration/local/bin/iadd

30 lines
992 B
Plaintext
Raw Permalink Normal View History

2021-09-09 10:19:16 +02:00
#!/bin/sh
tmp="$(mktemp)"
trap "rm -f $tmp" EXIT KILL
add_file="${1:-${LEDGER_ADD_FILE:-$LEDGER_FILE}}"
description="$(hledger descriptions | sk -p 'description> ')" || exit
date="$(for d in $(seq -7 0); do date --iso -d "$d days"; done | sk -p 'date> ' --no-sort --tac)"
printf '\n%s %s\n' "$date" "$description" > "$tmp"
2021-10-27 14:11:27 +02:00
while account="$(hledger accounts desc:"$description" | sk -p "account> " )"; do
2021-09-09 10:19:16 +02:00
echo "$account"
2021-10-27 14:11:27 +02:00
default="$(hledger reg "^$account$" -O csv | xsv select amount | tail -1)"
read -p "price [$default]: " price
2021-09-09 10:19:16 +02:00
read -p 'comment: ' comment
if [ -n "$comment" ]; then
2021-10-27 14:11:27 +02:00
printf ' %-56s%10s ; %s\n' "$account" "${price:-$default}" "$comment" >> "$tmp"
2021-09-09 10:19:16 +02:00
else
2021-10-27 14:11:27 +02:00
printf ' %-56s%10s\n' "$account" "${price:-$default}" >> "$tmp"
2021-09-09 10:19:16 +02:00
fi
done
cat "$tmp" >> "$add_file"
# 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