-
Notifications
You must be signed in to change notification settings - Fork 3
/
hlfi
executable file
·107 lines (88 loc) · 3.09 KB
/
hlfi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
# hlfi - reporting tool for hledger project finances
# shellcheck shell=bash disable=SC2317
set -e
cd "$(dirname "$0")"
SCRIPT=$(basename "$0")
JOURNAL=oc.journal
PERIOD="quarterly from 1/1 to tomorrow"
line() { echo "--------------------------------------------------------------------------------"; }
help() { # show this help
line
cat <<EOF
hlfi - reporting tool for hledger project finances
Usage: hlfi [COMMAND]
Commands:
$(grep -E '^\w.*\(\) *{ *#' "$SCRIPT" | sed -e 's/() *{//' | column -t -s'#')
CMD run other hledger commands on the hledger project's journal
Add hledger options to customise reports.
EOF
}
bs() { # show balance sheet
hledger -f "$JOURNAL" bs --layout bare --pretty --drop 1 -p "$PERIOD" -E "$@"
}
is() { # show income statement
hledger -f "$JOURNAL" is --layout bare --pretty --drop 1 -p "$PERIOD" -S "$@"
}
a() { # show assets
hledger -f "$JOURNAL" bal type:al -H --layout bare --pretty --drop 1 -p "$PERIOD" -E "$@"
}
r() { # show revenues
hledger -f "$JOURNAL" bal type:r --layout bare --pretty --drop 1 -p "$PERIOD" -S --invert "$@"
}
x() { # show expenses
hledger -f "$JOURNAL" bal type:x --layout bare --pretty --drop 1 -p "$PERIOD" -S --invert "$@"
}
b-a() { # show assets bar chart
echo "Quarterly net worth:"
hledger-bar -v 200 -f "$JOURNAL" -Q type:al -H "$@"
}
b-r() { # show revenues bar chart
echo "Quarterly revenues:"
hledger-bar -v 40 -f "$JOURNAL" -Q type:r --invert "$@"
}
b-x() { # show expenses bar chart
echo "Quarterly expenses:"
hledger-bar -v 40 -f "$JOURNAL" -Q type:x --invert "$@"
}
# XXX with partial workaround for https://github.com/gooofy/drawilleplot/issues/4
l-a() { # show assets line chart
hledger -f "$JOURNAL" plot -- bal --depth=1 ^assets --historical --terminal --rcParams '{"figure.figsize":[8,3]}' --no-today -q --title "hledger assets" "$@" | sed 's/⠀/ /g'
}
l-r() { # show revenues line chart
hledger -f "$JOURNAL" plot -- bal --depth=1 ^revenues --monthly --invert --terminal --rcParams '{"figure.figsize":[8,3]}' --drawstyle 'steps-mid' --no-today -q --title "hledger monthly revenues" "$@" | sed 's/⠀/ /g'
}
l-x() { # show expenses line chart
hledger -f "$JOURNAL" plot -- bal --depth=1 ^expenses --monthly --terminal --rcParams '{"figure.figsize":[8,3]}' --drawstyle 'steps-mid' --no-today -q --title "hledger monthly expenses" "$@" | sed 's/⠀/ /g'
}
reports() { # show main README reports in terminal. Add -o html for HTML.
# avoid -t as it currently doesn't indent in HTML
bs "$@"
echo
is "$@"
echo
bs -Y -b2017 "$@"
echo
is -T -Y -b2017 "$@"
echo
}
barcharts() { # show main hledger-bar charts in terminal
b-a "$@"
echo
b-r "$@"
echo
b-x "$@"
echo
}
linecharts() { # show main hledger-plot charts in terminal
l-a "$@"
echo
l-r "$@"
echo
l-x "$@"
echo
}
if [[ $# -eq 0 ]]; then help # no args shows help
elif declare -f "$1" > /dev/null; then "$@"; # arg 1 selects a function above
else hledger -f "$JOURNAL" "$@"; fi # or fall through to hledger
exit