forked from zsh-users/zsh-completions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_pygmentize
142 lines (121 loc) · 5.57 KB
/
_pygmentize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#compdef pygmentize
# ------------------------------------------------------------------------------
# Copyright (c) 2012 Github zsh-users - http://github.com/zsh-users
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the zsh-users nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for pygmentize.
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Hideo Hattori <[email protected]>
#
# ------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------
_pygmentize() {
local context state line
_arguments -s -S \
'-h[prints help]:' \
'-V[prints the package version]:' \
'-L[lists lexers, formatters, styles or filters]:args:(lexers formatters styles filters):' \
'-f[formatter]:FORMATTER:_get_formatters' \
'-o[output file]:FILENAME:_gnu_generic' \
'(-h -V -L -f -o -S -F -H -g -l)-N[guesses and prints out a lexer name based solely on given filename]:FILENAME:_files:' \
'(-h -V -L -o -F -H -g -l -N)-S[style]:STYLE:_get_styles' \
'-F[filter]:STYLE:_get_filters' \
'-H[prints detailed help for the object <name> of type <type>]:' \
'(-g)-l[lexer]::LEXER:_get_lexers:' \
'(-l)-g[attempt to guess the lexer from the file contents]' \
'*:args:_gnu_generic'
}
_get_filters() {
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
if [[ -z "$cache_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy _pygmentize_caching_policy
fi
if ( [[ ${+_pygmentize_filters} -eq 0 ]] || _cache_invalid pygmentize_filters ) \
&& ! _retrieve_cache pygmentize_filters; then
_pygmentize_filters=(${${(f)"$(pygmentize -L filters | grep '* ' | cut -c3- | sed -e 's/:$//')"}})
_store_cache pygmentize_filters _pygmentize_filters
fi
local expl
_wanted pygmentize_filters expl 'pygmentize filters' compadd -a _pygmentize_filters
}
(( $+functions[_pygmentize_get_formatters] )) ||
_get_formatters() {
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
if [[ -z "$cache_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy _pygmentize_caching_policy
fi
if ( [[ ${+_pygmentize_formatter} -eq 0 ]] || _cache_invalid pygmentize_formatter ) \
&& ! _retrieve_cache pygmentize_formatter; then
_pygmentize_formatter=(${${(f)"$(pygmentize -L formatters | grep '* ' | cut -c3- | sed -e 's/, /\n/g' -e 's/:$//')"}})
_store_cache pygmentize_formatter _pygmentize_formatter
fi
local expl
_wanted pygmentize_formatter expl 'pygmentize formatters' compadd -a _pygmentize_formatter
}
_get_lexers() {
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
if [[ -z "$cache_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy _pygmentize_caching_policy
fi
if ( [[ ${+_pygmentize_lexer} -eq 0 ]] || _cache_invalid pygmentize_lexer ) \
&& ! _retrieve_cache pygmentize_lexer; then
_pygmentize_lexer=(${${(f)"$(pygmentize -L lexers | grep '* ' | cut -c3- | sed -e 's/, /\n/g' -e 's/:$//')"}})
_store_cache pygmentize_lexer _pygmentize_lexer
fi
local expl
_wanted pygmentize_lexer expl 'pygmentize lexers' compadd -a _pygmentize_lexer
}
_get_styles() {
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
if [[ -z "$cache_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy _pygmentize_caching_policy
fi
if ( [[ ${+_pygmentize_style} -eq 0 ]] || _cache_invalid pygmentize_style ) \
&& ! _retrieve_cache pygmentize_style; then
_pygmentize_style=(${${(f)"$(pygmentize -L styles | grep '* ' | cut -c3- | sed -e 's/:$//')"}})
_store_cache pygmentize_style _pygmentize_style
fi
local expl
_wanted pygmentize_style expl 'pygmentize styles' compadd -a _pygmentize_style
}
_pygmentize_caching_policy() {
local -a oldp
oldp=( "$1"(Nmh+24) ) # 24 hour
(( $#oldp ))
}
_pygmentize "$@"