From e1273aa5b57d3d6abf0ccdc7988fddd84e73af84 Mon Sep 17 00:00:00 2001 From: Fabian Winter Date: Sun, 29 Jul 2018 19:34:14 +0200 Subject: [PATCH 1/2] Re-add hledger completion Thanks to @Valodim, who licenced their old completion under Apache 2.0, as written in #585 --- src/_hledger | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 src/_hledger diff --git a/src/_hledger b/src/_hledger new file mode 100644 index 0000000..ebb48d2 --- /dev/null +++ b/src/_hledger @@ -0,0 +1,189 @@ +#compdef hledger + +# ------------------------------------------------------------------------------ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for hleder 0.23.2 ( http://hledger.org/ ) +# Last updated: 16.11.2014 +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Valodim ( https://github.com/Valodim ) +# +# ------------------------------------------------------------------------------ +# Notes +# ----- +# +# account completion depends on availability of a ~/.hledger.journal file +# +# ------------------------------------------------------------------------------ + + +local curcontext="$curcontext" curstate state line expl grp cmd ret=1 +typeset -a args +typeset -A opt_args + +args=( + '(- *)'{-h,--help}'[print help information]' + '(-f --file)'{-f,--file}'=[use a different input file]:input file:_files' + '--rules-file=[CSV conversion rules file]:rules file:_files' + '--alias=[display accounts named OLD as NEW]:alias specification' + '(-b --begin)'{-b,--begin}'=[include postings/txns on or after this date]:date' + '(-e --end)'{-e,--end}'=[include postings/txns before this date]:date' + '(-D --daily)'{-D,--daily}'[multiperiod/multicolumn report by day]' + '(-W --weekly)'{-W,--weekly}'[multiperiod/multicolumn report by week]' + '(-M --monthly)'{-M,--monthly}'[multiperiod/multicolumn report by month]' + '(-Q --quarterly)'{-Q,--quarterly}'[multiperiod/multicolumn report by quarter]' + '(-Y --yearly)'{-Y,--yearly}'[multiperiod/multicolumn report by year]' + '(-p --period)'{-p,--period}'=[set start date, end date, and/or reporting interval all at once]' + '(-C --cleared)'{-C,--cleared}'[include only cleared postings/txns]' + '(-U --uncleared)'{-U,--uncleared}'[include only uncleared postings/txns]' + '(-R --real)'{-R,--real}'[include only non-virtual postings]' + '(--depth)--depth=[hide accounts/postings deeper than N]:depth' + '(-E --empty)'{-E,--empty}'[show empty/zero things which are normally omitted]' + '(-B --cost)'{-B,--cost}'[show amounts in their cost price'\''s commodity]' +) + +_arguments -C "$args[@]" -A "-*" \ + '(- *)--version[print version information]' \ + '--debug[show debug output]' \ + '1: :->cmds' \ + '*:: :->args' && ret=0 + +while (( $#state )); do + curstate=$state + shift state + case $curstate in + cmds) + typeset -a cmds + cmds=( + 'print:show transaction entries' + 'accounts:show account names' + 'balance:show accounts and balances (bal)' + 'register:show postings and running total (reg)' + 'incomestatement:show an income statement (is)' + 'balancesheet:show a balance sheet (bs)' + 'cashflow:show a cashflow statement (cf)' + 'activity:show an ascii barchart of posting counts per interval' + 'stats:show some journal statistics' + ) + _describe 'subcommands' cmds && ret=0 + ;; + args) + : $words + local cmd=$words[1] + (( $+cmd )) || return 1 + # curcontext="${curcontext%:*:*}:$service-$cmd:" + case $cmd in + accounts) + args+=( + '(--tree)--tree[show accounts as a tree (default in simple reports)]' + '(--flat)--flat[show accounts as a list (default in multicolumn)]' + '(--drop)--drop=[flat mode, omit N leading account name parts]:drop n' + ) + ;; + activity) + ;; + bal|balance) + args+=( + '(--tree)--tree[show accounts as a tree (default in simple reports)]' + '(--flat)--flat[show accounts as a list (default in multicolumn)]' + '(--drop)--drop=[in flat mode, omit N leading account name parts]:drop n' + '(--format)--format=[in tree mode, use this custom line format]:custom line format' + '(--no-elide)--no-elide[tree mode, do not squash boring parent accounts]' + '(--no-total)--no-total[do not show the final total]' + '(--cumulative)--cumulative[multicolumn mode, show accumulated ending balances]' + '(-H --historical)'{-H,--historical}'[multicolumn mode, show historical ending balances]' + ) + ;; + cashflow|cf|balancesheet|bs|incomestatement|is) + args+=( + '(--flat)--flat[show accounts as a list (default in multicolumn)]' + '(--drop)--drop=[in flat mode, omit N leading account name parts]:drop n' + ) + ;; + print) + ;; + register|reg) + args+=( + '(-H --historical)'{-H,--historical}'[include prior postings in the running total]' + '(-A --average)'{-A,--average}'[show a running average instead of the running total]' + '(-r --related)'{-r,--related}'[show postings'\'' siblings instead]' + '(-w --width)'{-w,--width}'=[set output width to 120, or N]:width (default 80)' + ) + ;; + stats) + ;; + # fallback to _default + *) _arguments -C -A "-*" "$args[@]" \ + '*: :_default' && ret=0 + continue + esac + _arguments -C -A "-*" "$args[@]" \ + '*:query patterns:->query' && ret=0 + ;; + query) + + local -a accs keywords + keywords=( + 'code\::match by transaction code' + 'desc\::match transaction descriptions' + 'tag\::match by tag name' + 'depth\::match at or above depth' + 'status\::match cleared/uncleared transactions' + 'real\::match real/virtual transactions' + 'empty\::match if amount is/is not zero' + 'amt\::match transaction amount' + ) + if compset -P 'amt:'; then + _message 'match amount (<, <=, >, >=, add sign for non-absolute match)' && ret=0 + continue + fi + if compset -P '(#b)(code|desc|tag|depth|status|real|empty):'; then + _message "'$match[1]' parameter" && ret=0 + continue + fi + + accs=( ${(f)"$(_call_program hledger hledger accounts $PREFIX 2>/dev/null)"} ) + if (( $? )); then + _message "error fetching accounts from hledger" + fi + + # decided against partial matching here. these lines can + # be uncommented to complete subaccounts hierarchically + # (add -S '' -q to the compadd below, too) + # if compset -P '(#b)(*):'; then + # accs=( ${(M)accs:#$match[1]:*} ) + # accs=( ${accs#$IPREFIX} ) + # fi + # accs=( ${accs%%:*} ) + + _wanted accounts expl "accounts" compadd -a accs && ret=0 + _describe "matcher keywords" keywords -S '' && ret=0 + + # not is special, it doesn't need the -S '' + keywords=( + 'not:negate expression' + ) + _describe "matcher keywords" keywords && ret=0 + + ;; + esac +done + +return ret From c66a6b1c2760a9f6e1ae7929b5483585e6426999 Mon Sep 17 00:00:00 2001 From: Fabian Winter Date: Sun, 29 Jul 2018 19:53:34 +0200 Subject: [PATCH 2/2] Update hledger completion There have been some changes in the last four years. I included what seemed to me the most important commands and parameters. --- src/_hledger | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/_hledger b/src/_hledger index ebb48d2..3223d37 100644 --- a/src/_hledger +++ b/src/_hledger @@ -16,14 +16,15 @@ # Description # ----------- # -# Completion script for hleder 0.23.2 ( http://hledger.org/ ) -# Last updated: 16.11.2014 +# Completion script for hleder 1.10 ( http://hledger.org/ ) +# Last updated: 29.07.2018 # # ------------------------------------------------------------------------------ # Authors # ------- # # * Valodim ( https://github.com/Valodim ) +# * fdw ( https://github.com/fdw ) # # ------------------------------------------------------------------------------ # Notes @@ -43,6 +44,7 @@ args=( '(-f --file)'{-f,--file}'=[use a different input file]:input file:_files' '--rules-file=[CSV conversion rules file]:rules file:_files' '--alias=[display accounts named OLD as NEW]:alias specification' + '--anon=[anonymize accounts and payees' '(-b --begin)'{-b,--begin}'=[include postings/txns on or after this date]:date' '(-e --end)'{-e,--end}'=[include postings/txns before this date]:date' '(-D --daily)'{-D,--daily}'[multiperiod/multicolumn report by day]' @@ -57,6 +59,9 @@ args=( '(--depth)--depth=[hide accounts/postings deeper than N]:depth' '(-E --empty)'{-E,--empty}'[show empty/zero things which are normally omitted]' '(-B --cost)'{-B,--cost}'[show amounts in their cost price'\''s commodity]' + '(-V --value)'{-V,--value}'[converts reported amounts to the current market value]' + '(-I --ignore-assertions'{-I,--ignore-assertions}'[ignore any failing balance assertions]' + '--forecast=[apply periodic transaction rules to generate future transactions]' ) _arguments -C "$args[@]" -A "-*" \ @@ -72,15 +77,19 @@ while (( $#state )); do cmds) typeset -a cmds cmds=( - 'print:show transaction entries' + 'print:show transaction entries (p, txns)' 'accounts:show account names' - 'balance:show accounts and balances (bal)' - 'register:show postings and running total (reg)' + 'balance:show accounts and balances (b, bal)' + 'register:show postings and running total (r, reg)' 'incomestatement:show an income statement (is)' 'balancesheet:show a balance sheet (bs)' 'cashflow:show a cashflow statement (cf)' 'activity:show an ascii barchart of posting counts per interval' 'stats:show some journal statistics' + 'add:prompt for transactions and add them to the journal' + 'close:print closing/opening transactions that bring some or all account balances to zero and back' + 'stats:show some journal statistics' + 'tags:list all the tag names used in the journal' ) _describe 'subcommands' cmds && ret=0 ;; @@ -141,6 +150,7 @@ while (( $#state )); do local -a accs keywords keywords=( + 'acct\::match account names' 'code\::match by transaction code' 'desc\::match transaction descriptions' 'tag\::match by tag name' @@ -149,6 +159,7 @@ while (( $#state )); do 'real\::match real/virtual transactions' 'empty\::match if amount is/is not zero' 'amt\::match transaction amount' + 'cur\::match by currency' ) if compset -P 'amt:'; then _message 'match amount (<, <=, >, >=, add sign for non-absolute match)' && ret=0