From a70c70764bcfe3e772477bd842dc0bc4e21af954 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Sat, 23 Jan 2021 22:47:04 +0100 Subject: [PATCH] add shop script for repeated visits to the same shop --- local/bin/shop | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 local/bin/shop diff --git a/local/bin/shop b/local/bin/shop new file mode 100755 index 0000000..23c9266 --- /dev/null +++ b/local/bin/shop @@ -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"