Skip to content

Commit

Permalink
first draft of new zsh completion
Browse files Browse the repository at this point in the history
  • Loading branch information
geier committed May 5, 2014
1 parent d565ca5 commit b97b554
Showing 1 changed file with 57 additions and 27 deletions.
84 changes: 57 additions & 27 deletions misc/__khal
Original file line number Diff line number Diff line change
@@ -1,38 +1,68 @@
#compdef khal
#
local opts actions config
# vim: ft=zsh sw=2 ts=2

_accounts() {
local accounts
accounts=( ${${(f)"$(command khal --list-accounts 2> /dev/null)"}/[$'\n']##/} )
compadd "$a" ${(kv)=accounts}
_calendars() {
local accounts
accounts=( ${${(f)"$(command khal printcalendars 2> /dev/null)"}/[$'\n']##/} )
compadd "$a" ${(kv)=accounts}
}

actions=(
--help -h
--version -v
--sync
-i --import
--new
)

config=(
-a --acount
--config -c
--debug
local ret=1 state

local -a common_ops
common_ops=(
{-h,--help}"[show help]"
{-v,--verbose}"[give more output]"
{-V,--version}"[show version and exit]"
{-q,--quiet}"[give less output]"
{-c,--config=}"[config file]:filename:_files"
)

opts=(
"($actions)"{--import,-i}'[import icalendar from FILE or STDIN]'
"($actions)"--sync'[sync with remote servers]'
"($actions $config)"{--help,-h}'[show help and exit]'
"($actions $config)"{--version,-v}'[show version number and exit]'
"($actions $config)"--new'[add a new event]'
"(-a)"-a'[specify account]:account name:_accounts'
"(-c --config --help)"{--config,-c}'[an alternate configuration file]:config file:_files'
)
_directories () {
_wanted directories expl directory _path_files -/ "$@" -
}

typeset -A opt_args
_arguments \
':subcommand:->subcommand' \
$common_ops \
'*::options:->options' && ret=0

case $state in
subcommand)
local -a subcommands
subcommands=(
"calendar:show calendar"
"agenda:show agenda"
"interactive:open the interactive calendar"
"new:add a new event"
"printcalendars:print all configured calendars"
)

_describe -t subcommands 'khal subcommands' subcommands && ret=0
;;

options)
local -a args
args=(
$common_ops
)

case $words[1] in
calendar | agenda | interactive)
args+=(
"-a=[use this calendar]:calendars:_calendars"
"-b=[do not use this calendar]:calendars:_calendars"
)
;;

esac

_arguments $args && ret=0
;;
esac

_arguments $opts[@]
return ret

# vim: ft=zsh

0 comments on commit b97b554

Please sign in to comment.