2
0
mirror of https://github.com/sharkdp/bat synced 2024-11-16 21:25:56 +00:00

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,10 +1,28 @@
#compdef bat
# FIXME: help me with the subcommand `cache`, zsh completion is hard as hell
local -a args
local state
local context state state_descr line
typeset -A opt_args
args=(
(( $+functions[_cache_subcommand] )) ||
_cache_subcommand() {
local -a args
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`)'
'(-l --language)'{-l+,--language=}'[Set the language for syntax highlighting]:<language>:->language'
@ -29,11 +47,11 @@ args=(
'(: -)'{-h,--help}'[Print this help message]'
'(: -)'{-V,--version}'[Show version information]'
'*: :_files'
)
)
_arguments -S -s $args
_arguments -S -s $args
case "$state" in
case "$state" in
language)
local IFS=$'\n'
local -a languages
@ -53,4 +71,21 @@ case "$state" in
style)
_values -s , 'style' auto full plain changes header grid numbers snip
;;
esac
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