LoginSignup
1
0

Ledger CLI コマンド備忘録

Last updated at Posted at 2024-03-05

コマンド備忘録

私がzshの記録に頼るのが脆弱と思いここに書き写すコマンド例です。-X CHFはコモディティをCHFに変換するコマンドなので日本にいるなら-X JPYとかか外貨あんまりないなら--marketがいい気がします。

B/Sがわかるやつ

2023 Q3時点での B/S。家計簿の場合Equity (純資産)にほぼ意味はないので割愛しています。

oneliner

$ ledger -f root.ledger bal -X CHF "^Assets:" "^Liabilities:" --current --now=2023-10-01

改行あり

$ ledger -f root.ledger bal "^Assets:" "^Liabilities:" \
  -X CHF \
  --current \
  --now=2023-10-01

--now=... を削除したら現時点での数字になる。

一年のP/L

oneliner

ledger -f filter/profit_loss.ledger reg --historical --period "from 2023-01-01 to 2024-01-01" ^Expenses: ^Income: -X CHF -M --format="%(quoted(date)),%(quoted(display_account)),%(quoted(quantity(scrub(display_amount))))\n" > /tmp/2023.csv

改行あり

ledger -f filter/profit_loss.ledger \
  reg ^Expenses: ^Income: \
  --historical \
  --period "from 2023-01-01 to 2024-01-01" \
  -X CHF -M \
  --format="%(quoted(date)),%(quoted(display_account)),%(quoted(quantity(scrub(display_amount))))\n" > /tmp/2023.csv

解説

filter/profit_loss.ledgeraliasを使って費用の分類を仕込んでる。-M(--monthly)は月ごとの集計を出すコマンド。

--historicalはレートが変動しても再計算しないオプション。B/Sなら再計算する意味はあるけどP/Lなら意味ないのでつけたほうがいい。

TODO: <Adjustment>が無視できない金額で出てくるがこれはどうしたら

値付きタグでの絞り込み

$ ledger -f root.ledger reg --limit '(tag(/travel/) =~ /202302-foobar/)' -X CHF --historical

同じくP/Lなので--historicalをつけている。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0