Skip to content

Instantly share code, notes, and snippets.

@ony
Last active December 22, 2018 08:18
Show Gist options
  • Save ony/fb81453d31004e322fdbe379fa3b31f0 to your computer and use it in GitHub Desktop.
Save ony/fb81453d31004e322fdbe379fa3b31f0 to your computer and use it in GitHub Desktop.
Sample of building pipeline of hledger-rewrite
#!/bin/bash
budget_buckets() {
if [[ $# -eq 0 ]]; then
cat # no more re-writes
else
# parse next entry
local account="${1%% -> *}"
local budget="Budget:${1##* -> }"
shift
# build current query
local query=("$account" "${ignores[@]}")
# prepare negative query for subsequent requests
local ignores=("${ignores[@]}" and "not:$account")
# spawn rewriter
hledger-rewrite -f- "${query[@]}" \
--add-posting "($budget) *-1" \
| budget_buckets "$@" # rewrite with rest of entries
fi
}
buckets=(
Expenses:Food
Expenses:Taxes
Expenses:Housing:Rent
'Expenses:Housing:Internet -> Expenses:Communications'
Expenses:Housing
Expenses:Medicine
'Expenses:Grocery -> Expenses:Supplies'
Expenses:Supplies
Expenses:Health
'Expenses:Phone -> Expenses:Communications'
'Expenses:Delivery -> Expenses:Operations'
'Expenses:Bank:Fee -> Expenses:Operations'
Expenses
)
hledger print "$@" | budget_buckets "${buckets[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment