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)

  • @PracticalReputationOP
    link
    English
    2
    edit-2
    8 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