add completion for 'cache' subcommand

This commit is contained in:
Kienyew 2020-08-29 23:19:42 +08:00 committed by David Peter
parent 222e080ce7
commit 9885d4ebf0

View File

@ -1,9 +1,27 @@
#compdef bat
# FIXME: help me with the subcommand `cache`, zsh completion is hard as hell
local context state state_descr line
typeset -A opt_args
(( $+functions[_cache_subcommand] )) ||
_cache_subcommand() {
local -a args
local state
args=(
'(-b --build -c --clear)'{-b,--build}'[Initialize or update the syntax/theme cache]'
'(-b --build -c --clear)'{-c,--clear}'[Remove the cached syntax definitions and themes]'
'(--source)'--source='[Use a different directory to load syntaxes and themes from]:directory:_files -/'
'(--target)'--target='[Use a different directory to store the cached syntax and theme set]:directory:_files -/'
'(--blank)'--blank'[Create completely new syntax and theme sets)]'
'(: -)'{-h,--help}'[Prints help information]'
'*: :'
)
_arguments -S -s $args
}
(( $+functions[_bat_main] )) ||
_bat_main() {
local -a args
args=(
'(-A --show-all)'{-A,--show-all}'[Show non-printable characters (space, tab, newline, ..)]'
{-p,--plain}'[Show plain style (alias for `--style=plain`)]:When `-p` is used twice (`-pp`), it also disables automatic paging (alias for `--style=plain --paging=never`)'
@ -54,3 +72,20 @@ case "$state" in
_values -s , 'style' auto full plain changes header grid numbers snip
;;
esac
}
# first positional argument
if (( ${#words} == 2 )); then
_values subcommand cache
_bat_main
else
case $words[2] in
cache)
_cache_subcommand
;;
*)
_bat_main
;;
esac
fi