Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zsh completion #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions completion/zsh/_t
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#compdef t
#description script for working with ledger-cli's timelog/timesheet format

local curcontext="$curcontext" state state_descr line

local -a commands
commands=(
'in:clock into project or last project'
'out:clock out of project'
'sw:switch projects'
'switch:switch projects'
'bal:show balance'
'hours:show balance for today'
'edit:edit timelog file'
'cur:show currently open project'
'last:show last closed project'
'grep:grep timelog for argument'
'cat:show timelog'
'less:show timelog in pager'
'timelog:show timelog file'
)

local curledger="${TIMELOG:-${HOME}/.timelog.ldg}"

# Future todo: use a zstyle to define a glob or list of files of historical
# ledgers, and zsh caching system to cache the parsed projects from those, so
# that previous files' projects can be used too.

_arguments -C : ':command:->command' '*::projects:->projects'
case "$state" in
(command)
_describe -t commands 'ledger timesheet t timelog commands' commands
;;
(projects)
case "${line[1]}" in
(in|out|sw|switch)
local -a projects
# i 2017-07-30 18:49:19 project:subproject:subsub
projects=( ${${(M)${(f)"$(< $curledger )"}:#i *}##i ????-??-?? ??:??:?? } )
#local mostrecent secondmost
#mostrecent="${projects[-1]}"
#secondmost="${projects[-2]}"
# In future, for sw/switch bias for secondmost, for others bias for most
# Need to figure out the zsh compsys to say "all these are valid, but prefer this one"
typeset -U projects
_wanted projects expl 'existing timelog projects' compadd -a projects
;;
(grep)
_arguments '*:pattern to grep timelog file for: '
;;
(*)
;;
esac
;;
esac