add shop script for repeated visits to the same shop

This commit is contained in:
Felix Van der Jeugt 2021-01-23 22:47:04 +01:00
parent 268a90b940
commit a70c70764b
No known key found for this signature in database
GPG Key ID: 58B209295023754D
1 changed files with 29 additions and 0 deletions

29
local/bin/shop Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
shop="$1"
askwithdefault() {
read -p "$1 [$2] " answer
echo "${answer:-$2}"
}
transaction="$(mktemp)"
trap "rm '$transaction'" EXIT KILL
exec 3> "$transaction"
date="$(askwithdefault 'Transaction date?' "$(date +'%Y-%m-%d')")"
printf '%s %s\n' "$date" "$shop" >&3
while account="$(hledger accounts desc:"$shop" | sk)"; do
read -p "Price? " price
read -p "Comment? " comment
printf " %s%$((66 - ${#account}))s" "$account" "€$price" >&3
if [ -n "$comment" ]; then
printf ' ; %s\n' "$comment" >&3
else
printf '\n' >&3
fi
done
exec 3>&-
cat "$transaction"