diff --git a/local/bin/iadd b/local/bin/iadd index 994614c..6aae0a9 100755 --- a/local/bin/iadd +++ b/local/bin/iadd @@ -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"