blob: 18995bed4a8e0d04636cdc6f281c0539ce8a0035 (
plain) (
blame)
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
|
# Ledger
alias ledger='noglob ledger'
alias ltoday='noglob ledger register --period today'
alias ldays='noglob ledger register --begin "last day"'
alias lweek='noglob ledger register --begin "last 7 days"'
alias balc='bal --current --aux-date'
alias lpending='ledger register --pending'
alias luncleared='ledger register --uncleared --begin "last 30 days"'
alias lcash='ledger balance Expenses:Cash'
alias budget='ledger budget --exchange R ^Expenses and not ^Expenses:Cash'
alias budget-month='ledger budget --period "this month" --exchange R ^Expenses and not ^Expenses:Cash'
alias ele="vim '$HOME/Dropbox/ledger/data/current.ledger'"
alias ledger-assets='ledger balance --exchange R --depth 3 --sort "-abs(display_total)" "^Assets:" "^Liabilities:"'
_ledger_smartcase_expr() {
echo "$1" | sed -r 's/[A-Z]/.*&/g'
}
bal() {
if [ $# -eq 0 ] || [[ $1 =~ [-].+ ]] ; then
ledger balance --format '%(account)\n' ^Assets |
head -n-1 | sort |
fzf --multi --preview "ledger balance $* {+}" |
xargs ledger balance $*
elif [ $# -eq 1 ] ; then
ledger balance \( ^Assets ^Liabilities \) and $(_ledger_smartcase_expr "$*")
else
ledger balance \( ^Assets ^Liabilities \) and $*
fi
}
lx() {
local entry=$(ledger xact $*)
local fn="$HOME/Dropbox/ledger/data/current.ledger"
local reply
echo "$entry"
vared -p "Is it ok? (Y/n) " -c reply
case "$reply" in
y|Y|"")
echo "\n$entry" >> "$fn";;
esac
}
budgets() {
read -r -d '' preview_command <<EOC
ledger budget --force-color -p {} --exchange R ^Expenses and not ^Expenses:Cash
echo
echo
ledger balance --force-color -p {} --exchange R --historical --depth 2 --sort "-abs(display_total)" \( ^Expenses and not ^Expenses:Cash \) ^Income
EOC
(
start_year=2013
start_month=11
end_year=$(date +%Y)
end_month=$(date +%m)
for year in $(seq "$start_year" "$end_year"); do
[ "$year" = "$start_year" ] && s_month="$start_month" || s_month=1
[ "$year" = "$end_year" ] && e_month="$end_month" || e_month=12
for month in $(seq "$s_month" "$e_month"); do
printf "%d-%02d\n" "$year" "$month"
done
echo "$year"
done
) | sort -r | fzf \
--reverse \
--exact \
--preview-window 90% \
--preview "$preview_command" \
| xargs -I{} sh -c "$preview_command"
}
expenses() {
account=$(ledger accounts -p 'last 6 months' '^Assets:' | fzf)
ledger balance "$@" '^Expenses:' and not '^Expenses:Cash$' and expr "any(account == '$account')"
}
ledger-by-note() {
note="$1"
shift
if [ $# -eq 0 ] ; then
ledger print expr "note =~ /$note/"
else
ledger "$@" expr "note =~ /$note/"
fi
}
alias expenses-month='expenses -p "this month"'
# vim: et ft=zsh :
|