on master help sign in
add completion for 'cache' subcommand
commit9885d4ebf0936bb078d418cb243237fabceb7f53 authorKienyew <aobi100bt@hotmail.com> dateSat 29 Aug 2020, 23:19 (6 years ago) parent222e080
1 file changed+90−55
assets/completions/bat.zsh+90−55
assets/completions/bat.zsh+90−55
@@ -1,56 +1,91 @@
11#compdef bat
2−# FIXME: help me with the subcommand `cache`, zsh completion is hard as hell
3−
4−local -a args
5−local state
6−
7−args=(
8− '(-A --show-all)'{-A,--show-all}'[Show non-printable characters (space, tab, newline, ..)]'
9− {-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`)'
10− '(-l --language)'{-l+,--language=}'[Set the language for syntax highlighting]:<language>:->language'
11− '(-H --highlight-line)'{-H,--highlight-line}'[Highlight lines N through M]:<N\:M>...'
12− '(--file-name)'--file-name'[Specify the name to display for a file]:<name>...:_files'
13− '(-d --diff)'--diff'[Only show lines that have been added/removed/modified]'
14− '(--diff-context)'--diff-context'[Include N lines of context around added/removed/modified lines when using `--diff`]:<N> (lines):()'
15− '(--tabs)'--tabs'[Set the tab width to T spaces]:<T> (tab width):()'
16− '(--wrap)'--wrap='[Specify the text-wrapping mode]:<when>:(auto never character)'
17− '(--terminal-width)'--terminal-width'[Explicitly set the width of the terminal instead of determining it automatically]:<width>'
18− '(-n --number)'{-n,--number}'[Show line numbers]'
19− '(--color)'--color='[When to use colors]:<when>:(auto never always)'
20− '(--italic-text)'--italic-text='[Use italics in output]:<when>:(always never)'
21− '(--decorations)'--decorations='[When to show the decorations]:<when>:(auto never always)'
22− '(--paging)'--paging='[Specify when to use the pager]:<when>:(auto never always)'
23− '(-m --map-syntax)'{-m+,--map-syntax=}'[Use the specified syntax for files matching the glob pattern]:<glob\:syntax>...'
24− '(--theme)'--theme='[Set the color theme for syntax highlighting]:<theme>:->theme'
25− '(: --list-themes --list-languages -L)'--list-themes'[Display all supported highlighting themes]'
26− '(--style)'--style='[Comma-separated list of style elements to display]:<components>:->style'
27− '(-r --line-range)'{-r+,--line-range=}'[Only print the lines from N to M]:<N\:M>...'
28− '(: --list-themes --list-languages -L)'{-L,--list-languages}'[Display all supported languages]'
29− '(: -)'{-h,--help}'[Print this help message]'
30− '(: -)'{-V,--version}'[Show version information]'
31− '*: :_files'
32−)
33−
34−_arguments -S -s $args
35−
36−case "$state" in
37− language)
38− local IFS=$'\n'
39− local -a languages
40− languages=( $(bat --list-languages | awk -F':|,' '{ for (i = 1; i <= NF; ++i) printf("%s:%s\n", $i, $1) }') )
41−
42− _describe 'language' languages
43− ;;
44−
45− theme)
46− local IFS=$'\n'
47− local -a themes
48− themes=( $(bat --list-themes | sort) )
49−
50− _values 'theme' $themes
51− ;;
52−
53− style)
54− _values -s , 'style' auto full plain changes header grid numbers snip
55− ;;
56−esac
2+
3+local context state state_descr line
4+typeset -A opt_args
5+
6+(( $+functions[_cache_subcommand] )) ||
7+_cache_subcommand() {
8+ local -a args
9+ 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+ '*: :'
17+ )
18+
19+ _arguments -S -s $args
20+}
21+
22+(( $+functions[_bat_main] )) ||
23+_bat_main() {
24+ local -a args
25+ 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`)]:When `-p` is used twice (`-pp`), it also disables automatic paging (alias for `--style=plain --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+ '(: -)'{-h,--help}'[Print this help message]'
48+ '(: -)'{-V,--version}'[Show version information]'
49+ '*: :_files'
50+ )
51+
52+ _arguments -S -s $args
53+
54+ case "$state" in
55+ language)
56+ local IFS=$'\n'
57+ local -a languages
58+ languages=( $(bat --list-languages | awk -F':|,' '{ for (i = 1; i <= NF; ++i) printf("%s:%s\n", $i, $1) }') )
59+
60+ _describe 'language' languages
61+ ;;
62+
63+ theme)
64+ local IFS=$'\n'
65+ local -a themes
66+ themes=( $(bat --list-themes | sort) )
67+
68+ _values 'theme' $themes
69+ ;;
70+
71+ style)
72+ _values -s , 'style' auto full plain changes header grid numbers snip
73+ ;;
74+ esac
75+}
76+
77+# first positional argument
78+if (( ${#words} == 2 )); then
79+ _values subcommand cache
80+ _bat_main
81+else
82+ case $words[2] in
83+ cache)
84+ _cache_subcommand
85+ ;;
86+
87+ *)
88+ _bat_main
89+ ;;
90+ esac
91+fi