-
Notifications
You must be signed in to change notification settings - Fork 490
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
Feature Request: Command aliases #2284
Comments
Interesting suggestion, thanks, @Pranshugoyal 🙏 |
Another reason I just bumped into which brought me searching for this is… assuming a complex 1 ledger where you finally figure out (through trial and error) the perfect options soup for the report you've wanted. It would be amazing to alias this report to something memorable. Footnotes
|
Couldn't agree more. I use a wrapper script: #!/bin/sh
ledgerBin="${LEDGERBIN:-.unwrapped-ledger}"
ledgerFile="${LEDGERFILE:-$HOME/notes/ledger/postings.ledger}"
get_flags() {
# Get flags for each preset report
case "$1" in
"daily") echo "daily --budget --period this month -l \"not (payee =~ /Monthly Budget/)\"" ;;
"net") echo "not ^equity and not ^expenses and not ^income and not ^funds" ;;
"status") echo "not ^equity and not ^expenses and not ^income" ;;
esac
}
cmd="$ledgerBin"
case "$1" in
"edit")
cmd="$EDITOR $ledgerFile" && shift
;;
"reg" | "register" | "bal" | "balance")
if [ "$2" = "daily" ] || [ "$2" = "net" ] || [ "$2" = "status" ]; then
cmd="$cmd $1 $(get_flags "$2")" && shift 2
fi
;;
"net" | "status")
cmd="ledger bal $1" && shift
;;
"daily")
cmd="ledger reg daily" && shift
;;
"report")
cmd="LEDGER_TERM='qt size 1280,720 persist' ledger-report" && shift
# If set to a preset report grab the flags from there
if [ "$1" = "net" ] || [ "$1" = "status" ]; then
cmd="$cmd register $(get_flags "$1") -J" && shift
fi
;;
"watch")
cmd="ls $ledgerFile | PAGER=cat entr -c ledger" && shift
;;
esac
# {*@Q} args as it is, refer to bash manual 3.5.3 Shell Parameter Expansion
eval "$cmd ${*@Q}" With which you sacrifice shell completion for of preset flags convenience. |
For recurring reports like monthly expenses or total taxable income over a financial year the way to go is to create a shell alias or function and provide it the time period while invoking.
It would be great if ledger could provide an alias creation feature like git or hg. That way the syntax of aliases and regular commands becomes consistent. If implemented well the feature may lend itself to also make it easy to create aliases for complex reports.
The text was updated successfully, but these errors were encountered: