Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an alignment/width option for hledger add #2008

Open
0branch opened this issue Feb 25, 2023 · 4 comments
Open

Provide an alignment/width option for hledger add #2008

0branch opened this issue Feb 25, 2023 · 4 comments
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. add

Comments

@0branch
Copy link

0branch commented Feb 25, 2023

I've been keeping my journal entries aligned using vim-ledger's LedgerAlign command, which aligns transactions on the decimal separator at a preconfigured column (default: 60).

When adding transactions with add, however, hledger uses the max account width for calculating alignment, meaning that entries added by the wizard are aligned internally but (typically) misaligned with prior entries.

Feature request: please provide --width=Int/-w Int option or something similar so that I can request that transactions are aligned consistently. If an account width exceeds this specification, its width can be used instead.

@0branch 0branch added the A-WISH Some kind of improvement request, hare-brained proposal, or plea. label Feb 25, 2023
@simonmichael
Copy link
Owner

Related:
#1045
#1052

@0branch
Copy link
Author

0branch commented Feb 25, 2023

Oh, my apologies for overlooking those.

And: thanks for hledger!

@simonmichael
Copy link
Owner

No problem. Glad you're enjoying it!

@akaleeroy
Copy link

akaleeroy commented May 8, 2023

My current workaround is to process journals with awk

#!/bin/bash

# Right-align the amounts in an hledger journal

# [Ed Morton's answer](https://stackoverflow.com/a/74765525/5266640)

# Usage:
# Check it:            ./align-journal.sh myjournal.j | less
# Output:              ./align-journal.sh myjournal.j > myjournal.aligned.j

awk '
  # Find lines with amounts to be aligned
  match($0,/^( {2,4}[^ ]+)  +([^;]+\y)?( *;.*)?/,a) {
    # Righ-align to column 60. 42 + 16 + 2
    $0 = sprintf("%-42s %16s%s", a[1], a[2], a[3])
  }
  { print }
' "$@"

Should make messy.j

# Test journal

; To test right alignment of amounts

* Recurring transactions

~ every 1st day of month  ! @ISP | Internet subscription with rented router
    expenses:communication:internet         5.00 EUR  ; ½ internet subscription fee
    expenses:communication:internet:router  0.50 EUR  ; ½ router rental fee
    assets:cash:eur                        -5.50 EUR

* Transactions

2018-01-01 @Payee | Internet
    expenses:communication:internet      123.00 EUR
    assets:cash:eur

2018-01-01 @Landlady | Rent
    expenses:housing:rent      321.00 EUR
    expenses:fees                2.50 EUR  ; Bank fee
    assets:bank:eur           -323.50 EUR

2016/01/01 Unit prices
   Expense:Foo  56 @ $6.00 ; a comment after a space
   Cash  $-336  ; a comment after two spaces

2022-01-01 Time
    skill      10000h
    time      -10000h
   weird    ; weird comment on posting without amount

2018-01-01 @Some things in life | Are free
    ; With and without comment
    expenses:misc:stuff                                       0  ; A comment
    expenses:misc:things                                      0
    assets:cash:eur

2022-12-25 @ACME Inc | Large amount test
    expenses:realestate           999999.99 EUR
    assets:bank:checking         -999999.99 EUR

... all neat

# Test journal

; To test right alignment of amounts

* Recurring transactions

~ every 1st day of month  ! @ISP | Internet subscription with rented router
    expenses:communication:internet                5.00 EUR  ; ½ internet subscription fee
    expenses:communication:internet:router         0.50 EUR  ; ½ router rental fee
    assets:cash:eur                               -5.50 EUR

* Transactions

2018-01-01 @Payee | Internet
    expenses:communication:internet              123.00 EUR
    assets:cash:eur

2018-01-01 @Landlady | Rent
    expenses:housing:rent                        321.00 EUR
    expenses:fees                                  2.50 EUR  ; Bank fee
    assets:bank:eur                             -323.50 EUR

2016/01/01 Unit prices
   Expense:Foo                                   56 @ $6.00 ; a comment after a space
   Cash                                               $-336  ; a comment after two spaces

2022-01-01 Time
    skill                                            10000h
    time                                            -10000h
   weird                                                   ; weird comment on posting without amount

2018-01-01 @Some things in life | Are free
    ; With and without comment
    expenses:misc:stuff                                   0  ; A comment
    expenses:misc:things                                  0
    assets:cash:eur

2022-12-25 @ACME Inc | Large amount test
    expenses:realestate                       999999.99 EUR
    assets:bank:checking                     -999999.99 EUR

Although currently this script fails to align everything. The following are left untouched:

  • directives
  • balance assertions
  • equity:opening/closing balance postings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. add
Projects
None yet
Development

No branches or pull requests

3 participants