1
1
#compdef {{PROJECT_EXECUTABLE}}
2
2
3
- local context state state_descr line
3
+ local curcontext="$curcontext" ret=1
4
+ local -a state state_descr line
4
5
typeset -A opt_args
5
6
6
7
(( $+functions[_{{PROJECT_EXECUTABLE}}_cache_subcommand] )) ||
7
8
_{{PROJECT_EXECUTABLE}}_cache_subcommand() {
8
9
local -a args
9
10
args=(
10
- '(-b --build -c --clear)'{-b,--build}'[Initialize or update the syntax/theme cache]'
11
- '(-b --build -c --clear)'{-c,--clear}'[Remove the cached syntax definitions and themes]'
12
- '( --source)'--source ='[Use a different directory to load syntaxes and themes from]:directory:_files -/'
13
- '( --target)'--target ='[Use a different directory to store the cached syntax and theme set]:directory:_files -/'
14
- '( --blank)'--blank'[Create completely new syntax and theme sets]'
15
- '(: -)'{-h,--help}'[Prints help information ]'
16
- '*: : '
11
+ '(-b --build -c --clear)'{-b,--build}'[initialize or update the syntax/theme cache]'
12
+ '(-b --build -c --clear)'{-c,--clear}'[remove the cached syntax definitions and themes]'
13
+ --source='[specify directory to load syntaxes and themes from]:directory:_files -/'
14
+ --target='[specify directory to store the cached syntax and theme set in ]:directory:_files -/'
15
+ --blank'[create completely new syntax and theme sets]'
16
+ --acknowledgements'[build acknowledgements.bin ]'
17
+ '(: -)'{-h,--help}'[show help information] '
17
18
)
18
19
19
20
_arguments -S -s $args
@@ -23,69 +24,79 @@ _{{PROJECT_EXECUTABLE}}_cache_subcommand() {
23
24
_{{PROJECT_EXECUTABLE}}_main() {
24
25
local -a args
25
26
args=(
26
- '(-A --show-all)'{-A,--show-all}'[Show non-printable characters (space, tab, newline, ..)]'
27
- '*'{-p,--plain}'[Show plain style (alias for `--style=plain`), repeat twice to disable disable automatic paging (alias for `--paging=never`)]'
28
- '(-l --language)'{-l+,--language=}'[Set the language for syntax highlighting]:<language>:->language'
29
- '(-H --highlight-line)'{-H,--highlight-line}'[Highlight lines N through M]:<N\:M>...'
30
- '(--file-name)'--file-name'[Specify the name to display for a file]:<name>...:_files'
31
- '(-d --diff)'--diff'[Only show lines that have been added/removed/modified]'
32
- '(--diff-context)'--diff-context'[Include N lines of context around added/removed/modified lines when using `--diff`]:<N> (lines):()'
33
- '(--tabs)'--tabs'[Set the tab width to T spaces]:<T> (tab width):()'
34
- '(--wrap)'--wrap='[Specify the text-wrapping mode]:<when>:(auto never character)'
35
- '(--terminal-width)'--terminal-width'[Explicitly set the width of the terminal instead of determining it automatically]:<width>'
36
- '(-n --number)'{-n,--number}'[Show line numbers]'
37
- '(--color)'--color='[When to use colors]:<when>:(auto never always)'
38
- '(--italic-text)'--italic-text='[Use italics in output]:<when>:(always never)'
39
- '(--decorations)'--decorations='[When to show the decorations]:<when>:(auto never always)'
40
- '(--paging)'--paging='[Specify when to use the pager]:<when>:(auto never always)'
41
- '(-m --map-syntax)'{-m+,--map-syntax=}'[Use the specified syntax for files matching the glob pattern]:<glob\:syntax>...'
42
- '(--theme)'--theme='[Set the color theme for syntax highlighting]:<theme>:->theme'
43
- '(: --list-themes --list-languages -L)'--list-themes'[Display all supported highlighting themes]'
44
- '(--style)'--style='[Comma-separated list of style elements to display]:<components>:->style'
45
- '(-r --line-range)'{-r+,--line-range=}'[Only print the lines from N to M]:<N\:M>...'
46
- '(: --list-themes --list-languages -L)'{-L,--list-languages}'[Display all supported languages]'
47
- '(: --no-config)'--no-config'[Do not use the configuration file]'
48
- '(: --no-custom-assets)'--no-custom-assets'[Do not load custom assets]'
49
- '(: --lessopen)'--lessopen'[Enable the $LESSOPEN preprocessor]'
50
- '(: --no-lessopen)'--no-lessopen'[Disable the $LESSOPEN preprocessor if enabled (overrides --lessopen)]'
51
- '(: --config-dir)'--config-dir'[Show bat'"'"'s configuration directory]'
52
- '(: --config-file)'--config-file'[Show path to the configuration file]'
53
- '(: --generate-config-file)'--generate-config-file'[Generates a default configuration file]'
54
- '(: --cache-dir)'--cache-dir'[Show bat'"'"'s cache directory]'
55
- '(: -)'{-h,--help}'[Print this help message]'
56
- '(: -)'{-V,--version}'[Show version information]'
57
- '*: :_files'
27
+ '(-A --show-all)'{-A,--show-all}'[show non-printable characters (space, tab, newline, ..)]'
28
+ --nonprintable-notation='[specify how to display non-printable characters when using --show-all]:notation:(caret unicode)'
29
+ \*{-p,--plain}'[show plain style (alias for `--style=plain`), repeat twice to disable disable automatic paging (alias for `--paging=never`)]'
30
+ '(-l --language)'{-l+,--language=}'[set the language for syntax highlighting]:language:->languages'
31
+ \*{-H+,--highlight-line=}'[highlight specified block of lines]:start\:end'
32
+ \*--file-name='[specify the name to display for a file]:name:_files'
33
+ '(-d --diff)'--diff'[only show lines that have been added/removed/modified]'
34
+ --diff-context='[specify lines of context around added/removed/modified lines when using `--diff`]:lines'
35
+ --tabs='[set the tab width]:tab width [4]'
36
+ --wrap='[specify the text-wrapping mode]:mode [auto]:(auto never character)'
37
+ '!(--wrap)'{-S,--chop-long-lines}
38
+ --terminal-width='[explicitly set the width of the terminal instead of determining it automatically]:width'
39
+ '(-n --number --diff --diff-context)'{-n,--number}'[show line numbers]'
40
+ --color='[specify when to use colors]:when:(auto never always)'
41
+ --italic-text='[use italics in output]:when:(always never)'
42
+ --decorations='[specify when to show the decorations]:when:(auto never always)'
43
+ --paging='[specify when to use the pager]:when:(auto never always)'
44
+ '(-m --map-syntax)'{-m+,--map-syntax=}'[map a glob pattern to an existing syntax name]: :->syntax-maps'
45
+ '(--theme)'--theme='[set the color theme for syntax highlighting]:theme:->themes'
46
+ '(: --list-themes --list-languages -L)'--list-themes'[show all supported highlighting themes]'
47
+ --style='[comma-separated list of style elements to display]: : _values "style [default]"
48
+ default auto full plain changes header header-filename header-filesize grid rule numbers snip'
49
+ \*{-r+,--line-range=}'[only print the specified line range]:start\:end'
50
+ '(* -)'{-L,--list-languages}'[display all supported languages]'
51
+ "--no-config[don't use the configuration file]"
52
+ "--no-custom-assets[don't load custom assets]"
53
+ '(--no-lessopen)'--lessopen'[enable the $LESSOPEN preprocessor]'
54
+ '(--lessopen)'--no-lessopen'[disable the $LESSOPEN preprocessor if enabled (overrides --lessopen)]'
55
+ '(* -)'--config-dir"[show bat's configuration directory]"
56
+ '(* -)'--config-file'[show path to the configuration file]'
57
+ '(* -)'--generate-config-file'[generate a default configuration file]'
58
+ '(* -)'--cache-dir"[show bat's cache directory]"
59
+ '(* -)'{-h,--help}'[show help information]'
60
+ '(* -)'{-V,--version}'[show version information]'
61
+ '*: :{ _files || compadd cache }'
58
62
)
59
63
60
- _arguments -S -s $args
64
+ _arguments -S -s $args && ret=0
61
65
62
66
case "$state" in
63
- language)
67
+ syntax-maps)
68
+ if ! compset -P '*:'; then
69
+ _message -e patterns 'glob pattern:language'
70
+ return
71
+ fi
72
+ ;& # fall-through
73
+
74
+ languages)
64
75
local IFS=$'\n'
65
76
local -a languages
66
77
languages=( $({{PROJECT_EXECUTABLE}} --list-languages | awk -F':|,' '{ for (i = 1; i <= NF; ++i) printf("%s:%s\n", $i, $1) }') )
67
78
68
- _describe 'language' languages
79
+ _describe 'language' languages && ret=0
69
80
;;
70
81
71
- theme)
72
- local IFS=$'\n'
73
- local -a themes
74
- themes=( $({{PROJECT_EXECUTABLE}} --list-themes | sort) )
75
-
76
- _values 'theme' $themes
77
- ;;
82
+ themes)
83
+ local -a themes expl
84
+ themes=( ${(f)"$(_call_program themes {{PROJECT_EXECUTABLE}} --list-themes)"} )
78
85
79
- style)
80
- _values -s , 'style' default auto full plain changes header header-filename header-filesize grid rule numbers snip
86
+ _wanted themes expl 'theme' compadd -a themes && ret=0
81
87
;;
82
88
esac
89
+
90
+ return ret
83
91
}
84
92
85
93
case $words[2] in
86
94
cache)
87
95
## Completion of the 'cache' command itself is removed for better UX
88
96
## See https://github.com/sharkdp/bat/issues/2085#issuecomment-1271646802
97
+ shift words
98
+ (( CURRENT-- ))
99
+ curcontext="${curcontext%:*}-${words[1]}:"
89
100
_{{PROJECT_EXECUTABLE}}_cache_subcommand
90
101
;;
91
102
0 commit comments