aboutsummaryrefslogtreecommitdiffstats
path: root/src/_pygmentize
diff options
context:
space:
mode:
authorJulien Nicoulaud <julien.nicoulaud@gmail.com>2012-08-01 13:23:11 +0200
committerJulien Nicoulaud <julien.nicoulaud@gmail.com>2012-08-01 13:23:11 +0200
commit10ffeb0c153258896531b2b8939e94486d58b378 (patch)
treef735059d34c7f2ade7eb410643f39ecf402833d9 /src/_pygmentize
parentAdd call for deb and rpm packagers (diff)
downloadzsh-completions-10ffeb0c153258896531b2b8939e94486d58b378.tar
zsh-completions-10ffeb0c153258896531b2b8939e94486d58b378.tar.gz
zsh-completions-10ffeb0c153258896531b2b8939e94486d58b378.tar.bz2
zsh-completions-10ffeb0c153258896531b2b8939e94486d58b378.tar.lz
zsh-completions-10ffeb0c153258896531b2b8939e94486d58b378.tar.xz
zsh-completions-10ffeb0c153258896531b2b8939e94486d58b378.tar.zst
zsh-completions-10ffeb0c153258896531b2b8939e94486d58b378.zip
[BREAKING CHANGE] Move compdefs to own directory (to ease packaging and
avoid bloating users fpath with unneeded files such as README.md)
Diffstat (limited to 'src/_pygmentize')
-rw-r--r--src/_pygmentize142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/_pygmentize b/src/_pygmentize
new file mode 100644
index 0000000..6d2594f
--- /dev/null
+++ b/src/_pygmentize
@@ -0,0 +1,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 <hhatto.jp@gmail.com>
+#
+# ------------------------------------------------------------------------------
+# -*- 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 "$@"