Skip to content

Instantly share code, notes, and snippets.

@3tty0n
Last active August 28, 2017 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3tty0n/0ef541bb9fce758c4c064ce96ba83a91 to your computer and use it in GitHub Desktop.
Save 3tty0n/0ef541bb9fce758c4c064ce96ba83a91 to your computer and use it in GitHub Desktop.
completion for gol in zsh
#compdef gol
function _gol {
local context curcontext=$curcontext state line
declare -A opt_args
local ret=1
_arguments -C \
'(-h --help)'{-h,--help}'[show help]' \
'(-v --version)'{-v,--version}'[print the version]' \
'--datapath [/path/to/data/file (default: "~/.config/gol/links.json")]' \
'1: :__gol_commands' \
'*:: :->args' \
&& ret=0
case $state in
(args)
case $words[1] in
(open)
_arguments -C\
'1: :__gol_keys' \
&& ret=0
;;
(rm)
_arguments -C\
'1: :__gol_keys' \
&& ret=0
;;
(help|h)
__gol_commands && ret=0
;;
(*)
ret=0
;;
esac
;;
esac
return ret
}
function __gol_keys {
local -a _keys
_keys=( ${(@f)"$(_call_program keys gol ls)"} )
_describe -t keys Keys _keys
}
function __gol_commands {
local -a _c
_c=(
'add:add the key'
'rm:remove the key'
'ls:display keys'
'get:get the key'
'dump:run dump'
'open:open the key'
'peco:open the key in peco'
'server:start the gol server'
)
_describe -t commands Commands _c
}
_gol "$@"
compdef _gol gol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment