6
submitted 7 months ago* (last edited 7 months ago) by PracticalReputation@lemmy.world to c/plaintextaccounting@lemmy.world

Is there a way I could see my is view monthly, but from current date from each month? I.e. if I ran the command today I would see January to April where each month is showing expenses and incoming from 1-9, i.e. 1-9 January, 1-9 February, 1-9 March and so forth?

Idea is to have a comparison how expenses/income ratio is going compared to previous months at the "same time".

Like for January only I could $ hledger print -b $(date +%Y-)01-01 -e $(date +%Y)-01-$(date +%d)

you are viewing a single comment's thread
view the rest of the comments
[-] PracticalReputation@lemmy.world 2 points 7 months ago* (last edited 7 months ago)

Kind of got it as I started thinking about it after posting... Would be better as a oneliner set to an alias so one can add flags on the fly, but this works:

#!/usr/bin/env bash

# Where to save temporary journal
PROGRESS_JOURNAL_PATH="/tmp/progress.journal"

# Current month as number
MONTH=$(date +%m)
# Need to increment the month with one for loop to work
((MONTH++))

# Clean out the temp journal in case it already exists
echo -e "; Temporary progress journal\n" > "$PROGRESS_JOURNAL_PATH"

for ((COUNTER = 1 ; COUNTER < $MONTH ; COUNTER++)); do
  # Append each months transactions until current month within the same date range as today
  hledger print -b "$(date +%Y)-$COUNTER-01" -e "$(date +%Y)-$COUNTER-$(date +%d)" >> "$PROGRESS_JOURNAL_PATH"
done

# Print out the command that should run to output
echo "$ hledger -f $PROGRESS_JOURNAL_PATH is -t -M -A"
# Get the result
hledger -f "$PROGRESS_JOURNAL_PATH" is -t -M -A -S
this post was submitted on 09 Apr 2024
6 points (100.0% liked)

Plain Text Accounting

151 readers
1 users here now

Bookkeeping and accounting with plain text files and scriptable, command-line-friendly software, such as Ledger, hledger, or Beancount.

founded 1 year ago
MODERATORS