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

Feature Request: Command aliases #2284

Open
Pranshugoyal opened this issue Aug 29, 2023 · 3 comments
Open

Feature Request: Command aliases #2284

Pranshugoyal opened this issue Aug 29, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@Pranshugoyal
Copy link

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.

@afh
Copy link
Member

afh commented Aug 29, 2023

Interesting suggestion, thanks, @Pranshugoyal 🙏

@afh afh added the enhancement New feature or request label Aug 29, 2023
@igbanam
Copy link

igbanam commented Jun 3, 2024

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

  1. "complex" for me was trying to find my largest spend in a certain currency using a ledger with multiple currencies and commodities which convert magically™

@octvs
Copy link

octvs commented Jun 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants