use last price as default

This commit is contained in:
Felix Van der Jeugt 2021-10-27 14:11:27 +02:00
parent 2be2f4b077
commit 05172bef55
No known key found for this signature in database
GPG Key ID: 58B209295023754D

View File

@ -7,17 +7,16 @@ 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"
diff="0.00"
while account="$(hledger accounts desc:"$description" | sk -p "account ($diff)> " )"; do
while account="$(hledger accounts desc:"$description" | sk -p "account> " )"; do
echo "$account"
read -p "price ($diff): " price
default="$(hledger reg "^$account$" -O csv | xsv select amount | tail -1)"
read -p "price [$default]: " price
read -p 'comment: ' comment
if [ -n "$comment" ]; then
printf ' %-56s%10s ; %s\n' "$account" "$price" "$comment" >> "$tmp"
printf ' %-56s%10s ; %s\n' "$account" "${price:-$default}" "$comment" >> "$tmp"
else
printf ' %-56s%10s\n' "$account" "$price" >> "$tmp"
printf ' %-56s%10s\n' "$account" "${price:-$default}" >> "$tmp"
fi
diff="$(printf '(%s) - (%s)\n' "$diff" "$price" | bc)"
done
cat "$tmp" >> "$add_file"