;bin:justfile: make more chooser friendly, add help/pick/view
This commit is contained in:
parent
245178cac8
commit
969dea72ae
@ -136,6 +136,7 @@ Add hledger options to customise reports.
|
|||||||
|
|
||||||
<https://github.com/casey/just> is like [make](https://en.wikipedia.org/wiki/Make_(software)), but easier and more suitable for running commands.
|
<https://github.com/casey/just> is like [make](https://en.wikipedia.org/wiki/Make_(software)), but easier and more suitable for running commands.
|
||||||
It is a nice tool for organising financial reports and scripts!
|
It is a nice tool for organising financial reports and scripts!
|
||||||
|
More on [hledger and just](just.md).
|
||||||
|
|
||||||
Here is a [justfile](https://github.com/simonmichael/hledger/blob/master/bin/justfile)
|
Here is a [justfile](https://github.com/simonmichael/hledger/blob/master/bin/justfile)
|
||||||
reimplementing the `ft` and `tt` scripts more simply:
|
reimplementing the `ft` and `tt` scripts more simply:
|
||||||
|
|||||||
61
bin/justfile
61
bin/justfile
@ -2,22 +2,33 @@
|
|||||||
# * financial reports/scripts, runnable with https://github.com/casey/just
|
# * financial reports/scripts, runnable with https://github.com/casey/just
|
||||||
# (like make but simpler and more suitable for running commands.)
|
# (like make but simpler and more suitable for running commands.)
|
||||||
# ** PREAMBLE ------------------------------------------------------------
|
# ** PREAMBLE ------------------------------------------------------------
|
||||||
|
# XXX we don't quote HLEDGERARGS properly, so each one must be free of spaces
|
||||||
PERIOD := "1/1..tomorrow"
|
|
||||||
TODAY := `date +%Y-%m-%d`
|
|
||||||
|
|
||||||
just := "just -f " + justfile()
|
just := "just -f " + justfile()
|
||||||
@_help:
|
|
||||||
{{just}} -lu --list-heading=$'{{ file_name(justfile()) }} commands:\n'
|
# list the commands available
|
||||||
|
@help:
|
||||||
|
{{just}} -lu --list-heading=$'{{ file_name(justfile()) }} commands:\n\
|
||||||
|
HLEDGERARGS can be added to customise reports.\n\
|
||||||
|
NOTCHOOSABLE is a required dummy argument, write - for it. Eg: just browse -\n\
|
||||||
|
'
|
||||||
|
|
||||||
|
# interactively pick a command with the default chooser. Eg: just pick -
|
||||||
|
pick NOTCHOOSABLE:
|
||||||
|
{{just}} --choose
|
||||||
|
|
||||||
|
# interactively view command outputs with fzf and bkt. Eg: just view - --black
|
||||||
|
view NOTCHOOSABLE *FZFARGS:
|
||||||
|
{{just}} --choose --chooser="fzf --reverse --preview='bkt --ttl=15m --stale=15s -- just {}' {{FZFARGS}}"
|
||||||
|
|
||||||
# rerun the given command with watchexec whenever local files change
|
# rerun the given command with watchexec whenever local files change
|
||||||
watch CMD:
|
watch CMD:
|
||||||
watchexec -- {{just}} {{CMD}}
|
watchexec -- {{just}} {{CMD}}
|
||||||
|
|
||||||
# XXX HLEDGERARGS are not quoted properly; each one should be free of spaces
|
|
||||||
|
|
||||||
# ** IMPORT ------------------------------------------------------------
|
# ** IMPORT ------------------------------------------------------------
|
||||||
|
|
||||||
|
TODAY := `date +%Y-%m-%d`
|
||||||
|
|
||||||
# where to import most hledger transactions from
|
# where to import most hledger transactions from
|
||||||
IMPORTFILES := '\
|
IMPORTFILES := '\
|
||||||
wf-bchecking.csv.rules \
|
wf-bchecking.csv.rules \
|
||||||
@ -29,7 +40,7 @@ IMPORTFILES := '\
|
|||||||
'
|
'
|
||||||
|
|
||||||
# download auto-downloadable CSVs (paypal)
|
# download auto-downloadable CSVs (paypal)
|
||||||
@get-csv:
|
@get-csv NOTCHOOSABLE:
|
||||||
paypaljson | paypaljson2csv > paypal.csv
|
paypaljson | paypaljson2csv > paypal.csv
|
||||||
|
|
||||||
# import new downloaded transactions to the main journal, dry run
|
# import new downloaded transactions to the main journal, dry run
|
||||||
@ -37,13 +48,13 @@ IMPORTFILES := '\
|
|||||||
hledger import --dry-run {{IMPORTFILES}}
|
hledger import --dry-run {{IMPORTFILES}}
|
||||||
|
|
||||||
# import new downloaded transactions to the journal, logging and not printing errors
|
# import new downloaded transactions to the journal, logging and not printing errors
|
||||||
@import:
|
@import NOTCHOOSABLE:
|
||||||
date >>import.log
|
date >>import.log
|
||||||
@hledger import {{IMPORTFILES}} 2>>import.log || echo "Failed, check import.log"
|
@hledger import {{IMPORTFILES}} 2>>import.log || echo "Failed, check import.log"
|
||||||
echo "Now use ledger-mode's M-q to align entries."
|
echo "Now use ledger-mode's M-q to align entries."
|
||||||
|
|
||||||
# show prices for main commodities (default: today's)
|
# show prices for main commodities (default: today's)
|
||||||
@get-prices *PRICEHISTFETCHOPTS :
|
@get-prices NOTCHOOSABLE *PRICEHISTFETCHOPTS :
|
||||||
(pricehist fetch -o ledger -s {{TODAY}} alphavantage EUR/USD {{PRICEHISTFETCHOPTS}} | sed -E 's/EUR/€/') &
|
(pricehist fetch -o ledger -s {{TODAY}} alphavantage EUR/USD {{PRICEHISTFETCHOPTS}} | sed -E 's/EUR/€/') &
|
||||||
(pricehist fetch -o ledger -s {{TODAY}} alphavantage GBP/USD {{PRICEHISTFETCHOPTS}} | sed -E 's/GBP/£/') &
|
(pricehist fetch -o ledger -s {{TODAY}} alphavantage GBP/USD {{PRICEHISTFETCHOPTS}} | sed -E 's/GBP/£/') &
|
||||||
(pricehist fetch -o ledger -s {{TODAY}} alphavantage JPY/USD {{PRICEHISTFETCHOPTS}} | sed -E 's/JPY/¥/')
|
(pricehist fetch -o ledger -s {{TODAY}} alphavantage JPY/USD {{PRICEHISTFETCHOPTS}} | sed -E 's/JPY/¥/')
|
||||||
@ -52,6 +63,8 @@ IMPORTFILES := '\
|
|||||||
|
|
||||||
# ** REPORTS ------------------------------------------------------------
|
# ** REPORTS ------------------------------------------------------------
|
||||||
|
|
||||||
|
PERIOD := "1/1..tomorrow"
|
||||||
|
|
||||||
# show balance sheet
|
# show balance sheet
|
||||||
bs *HLEDGERARGS :
|
bs *HLEDGERARGS :
|
||||||
hledger bs --layout bare --pretty --drop 1 -p {{PERIOD}} -E -5 {{HLEDGERARGS}}
|
hledger bs --layout bare --pretty --drop 1 -p {{PERIOD}} -E -5 {{HLEDGERARGS}}
|
||||||
@ -106,18 +119,18 @@ forecast *HLEDGERARGS :
|
|||||||
|
|
||||||
# show a draft month-end household adjustment transaction for last month
|
# show a draft month-end household adjustment transaction for last month
|
||||||
household *HLEDGERARGS :
|
household *HLEDGERARGS :
|
||||||
env household "$($date -v-1m +%b)"
|
env household "$($date -v-1m +%b)"
|
||||||
|
|
||||||
# show consulting revenue
|
# show consulting revenue
|
||||||
consulting *HLEDGERARGS :
|
consulting *HLEDGERARGS :
|
||||||
hledger reg --invert 'revenues:(cw|ah)' -p {{PERIOD}} {{HLEDGERARGS}}
|
hledger reg --invert 'revenues:(cw|ah)' -p {{PERIOD}} {{HLEDGERARGS}}
|
||||||
|
|
||||||
# estimated-tax *HLEDGERARGS :
|
# estimated-tax *HLEDGERARGS :
|
||||||
# @echo "Federal estimated tax due for this year"
|
# @echo "Federal estimated tax due for this year"
|
||||||
# $(HLEDGER) register liabilities:personal:tax:federal:$(YEAR) --width=130
|
# $(HLEDGER) register liabilities:personal:tax:federal:$(YEAR) --width=130
|
||||||
# @echo State estimated tax due for this year:
|
# @echo State estimated tax due for this year:
|
||||||
# @$(HLEDGER) register liabilities:personal:tax:state:$(YEAR) --width=130
|
# @$(HLEDGER) register liabilities:personal:tax:state:$(YEAR) --width=130
|
||||||
# @echo
|
# @echo
|
||||||
|
|
||||||
# ** TIME REPORTS ------------------------------------------------------------
|
# ** TIME REPORTS ------------------------------------------------------------
|
||||||
|
|
||||||
@ -135,13 +148,15 @@ TIMELOGDATA := 'time-' + YEAR + '.timedot'
|
|||||||
# (This is better than touching the timelog file itself, which confuses editors.)
|
# (This is better than touching the timelog file itself, which confuses editors.)
|
||||||
#
|
#
|
||||||
# show time dashboard, redisplaying when timelog files change
|
# show time dashboard, redisplaying when timelog files change
|
||||||
tdash *HLEDGERARGS:
|
tdash NOTCHOOSABLE *HLEDGERARGS:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
dir=$(dirname "$TIMELOG")
|
dir=$(dirname "$TIMELOG")
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
opts= #--poll=10 # <- uncomment to fix symlinked files being ignored
|
opts= #--poll=10 # <- uncomment to fix symlinked files being ignored
|
||||||
watchexec $opts --no-vcs-ignore --filter-file=<(hledger -f "$TIMELOG" files | sed -E "s|$dir/||g") -c -r {{just}} tstatus
|
watchexec $opts --no-vcs-ignore \
|
||||||
|
--filter-file=<(hledger -f "$TIMELOG" files | sed -E "s|$dir/||g") \
|
||||||
|
-c -r {{just}} tstatus {{HLEDGERARGS}}
|
||||||
|
|
||||||
# show time dashboard, redisplaying every minute with watch
|
# show time dashboard, redisplaying every minute with watch
|
||||||
# dash-1m *HLEDGERARGS:
|
# dash-1m *HLEDGERARGS:
|
||||||
@ -169,9 +184,9 @@ tstatus *HLEDGERARGS:
|
|||||||
# Show the current day/week/month budget status.
|
# Show the current day/week/month budget status.
|
||||||
printf "Time plans:\n"
|
printf "Time plans:\n"
|
||||||
# calculate each period's budget from daily budget
|
# calculate each period's budget from daily budget
|
||||||
hledger -f "$TIMELOG" bal -1 -p 'daily today' --budget=Daily | tail +2
|
hledger -f "$TIMELOG" bal -1 -p 'daily today' --budget=Daily {{HLEDGERARGS}} | tail +2
|
||||||
hledger -f "$TIMELOG" bal -1 -p 'weekly this week' --budget=Daily | tail +2
|
hledger -f "$TIMELOG" bal -1 -p 'weekly this week' --budget=Daily {{HLEDGERARGS}} | tail +2
|
||||||
hledger -f "$TIMELOG" bal -1 -p 'monthly this month' --budget=Daily | tail +2
|
hledger -f "$TIMELOG" bal -1 -p 'monthly this month' --budget=Daily {{HLEDGERARGS}} | tail +2
|
||||||
# or use each period's specific budget
|
# or use each period's specific budget
|
||||||
# hledger -f "$TIMELOG" bal -p 'daily today' --budget=Daily -1 | tail +2
|
# hledger -f "$TIMELOG" bal -p 'daily today' --budget=Daily -1 | tail +2
|
||||||
# hledger -f "$TIMELOG" bal -p 'weekly this week' --budget=Weekly -1 | tail +2
|
# hledger -f "$TIMELOG" bal -p 'weekly this week' --budget=Weekly -1 | tail +2
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user