Created
February 8, 2019 23:08
-
-
Save schoettl/0d459347005661bbe7691116db7be4a6 to your computer and use it in GitHub Desktop.
In hledger register output, remove running-total column and invert amount optionally (for € commodity)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Remove running sum and optionally invert amounts. | |
# Call with -i as first arg to invert amount! | |
# All other args are passed to hledger register. | |
set -o errexit -o pipefail -o nounset | |
removeSum() { | |
sed -r -e 's/ +[^ ]+ €$//' | |
} | |
invertAmount() { | |
awk ' | |
/ -[0-9,.]+ €$/ { | |
print gensub(/(.*) -([0-9,.]+ €$)/, "\\1 \\2", 1) | |
next | |
}; | |
/ [0-9,.]+ €$/ { | |
print gensub(/(.*) ([0-9,.]+ €$)/, "\\1 -\\2", 1) | |
next | |
}; | |
1 # otherwise print' | |
} | |
main() { | |
if [[ $1 == -i ]]; then | |
shift | |
hledger register "$@" | removeSum | invertAmount | |
else | |
hledger register "$@" | removeSum | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment