Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: xmlstarlet completion
- X-seq: zsh-workers 42567
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: xmlstarlet completion
- Date: Fri, 30 Mar 2018 12:04:26 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1522418799; bh=seSA/jhg7UAJD1CljvCE2h5ve/SdZwQIcSxbON2o84A=; h=From:To:Subject:Date:From:Subject; b=LmCw1ZF8o9GoH+x2CogVucka1brgT9x5t3amQl4lp+bj0claR6yNKu6xNZ1FN6XnJyWUfF3xQLh9Azxt6ZsHzQNChMBTbcWxOJzR9Er4R3myJl+ehXYYGTdsCgkNpVCQGja9Fiu/amuMtNf42NFzIi0uLovI5UtkDxlEPwiroq0IBeAkIawTiYP1yq/JE3YfJYsNqXI8EEtFms94kYPVnblf7JqSEOo5vbTc3wSMPoolozd2FPMLpFHeEDPNqGq8h3QfE6YBQ0bHYLjtwDkSr8MjR/G/6WcGziwdg8eCPHQfcVYfI/HckODVXGywgS0gnArJedykhfqtIHBNWAysBA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
This is a new completion for xmlstarlet. I've had most of this sitting
around unfinished for many years so it isn't really new.
Oliver
diff --git a/Completion/Unix/Command/_xmlstarlet b/Completion/Unix/Command/_xmlstarlet
new file mode 100644
index 000000000..4c8257046
--- /dev/null
+++ b/Completion/Unix/Command/_xmlstarlet
@@ -0,0 +1,177 @@
+#compdef xmlstarlet xml
+
+local curcontext="$curcontext" ret=1
+local -a args state line suf
+
+args=( '(- *)--help[display usage information]' )
+_arguments -C -A "-*" $args \
+ '(-q --quiet)'{-q,--quiet}'[no error output]' \
+ "--no-doc-namespace[don't extract namespace bindings from input doc]" \
+ '!(--no-doc-namespace)--doc-namespace' \
+ '(-)--version[display version information]' \
+ '1:command:((
+ ed{,it}\:edit\ or\ update\ documents
+ sel{,ect}\:select\ date\ or\ query\ documents
+ tr{,ransform}\:transform\ documents\ using\ XSLT
+ val{,idate}\:validate\ documents
+ fo{,rmat}\:format\ documents
+ el{,ements}\:display\ element\ structure
+ {c14n,canonic}\:XML\ canonicalization
+ l{s,ist}\:list\ directory\ as\ XML
+ esc{,ape}\:escape\ special\ XML\ characters
+ unesc{,ape}\:unescape\ special\ XML\ characters
+ {pyx,xmln}\:convert\ XML\ into\ the\ line-oriented\ PYX\ format
+ {p2x,depyx}\:convert\ PYX\ into\ XML
+ ))' \
+ '*: :->args' && ret=0
+
+if [[ -n $state ]]; then
+ shift words
+ (( CURRENT-- ))
+ curcontext="${curcontext%:*:*}:$service-${words[1]}:"
+ case $words[1] in
+ el(|ements)|fo(|rmat)|sel(|ect)|c14n|canonic|xmln|pyx)
+ args+=( '1:file:_files -g "(#i)*.xml(-.)"' )
+ ;|
+ ed(|it)|sel(|ect))
+ args+=( '*-N[predefine namespaces]:namespace' )
+ ;|
+ c14n|canonic|ed(|it)|fo(|rmat)|sel(|ect)|tr(|ansform)|val(|idate))
+ args+=( '--net[allow fetching of DTDs or entities over network]' )
+ ;|
+ fo(|rmat)|tr(|ansform))
+ args+=( '(-o --omit-decl)'{-o,--omit-decl}'[omit XML declaration]' )
+ ;|
+
+ ed(|it))
+ args=(
+ '(opt)*'{-d,--delete}'[remove element]:xpath expression'
+ '(opt)*'{-i,--insert}'[add element before node matched by expression]:xpath expression - insert before matched node'
+ '(opt)*'{-a,--append}'[add element after node matched by expression]:xpath expression - insert after matched node'
+ '(opt)*'{-s,--subnode}'[add element as a child of node matched by expression]:xpath expression for parent modes'
+ '(opt)*'{-m,--move}'[move element]:xpath expression: :xpath expression'
+ '(opt)*'{-r,--rename}'[rename element]:xpath expression'
+ '(opt)*'{-u,--update}'[update element]:xpath expression'
+ '*:file:_files -g "(#i)*.xml(-.)"'
+ + opt $args
+ '(-P -S --pf --ps)'{-P,-S,--pf,--ps}'[preserve whitespace nodes]'
+ '(-O --omit-decl)'{-O,--omit-decl}'[omit XML declaration]'
+ '(-L --inplace)'{-L,--inplace}'[edit file inplace]'
+ )
+ if [[ -n ${${words[2,CURRENT-1]}[(r)-([ias]|-insert|-append|-subnode)]} ]]; then
+ args=(
+ '(opt)*'{-t,--type}'[specify type of node to add]:type:(elem text attr)'
+ '(opt)*'{-n,--name}'[specify name of node to add]:name'
+ $args
+ )
+ fi
+ if [[ -n ${${words[2,CURRENT-1]}[(r)-([iasru]|-insert|-append|-subnode|-rename|-update)]} ]]; then
+ args=( '(opt)*'{-v,--value}'[specify value of node to add or name of renamed node]:value' $args )
+ fi
+ ;;
+ el(|ements))
+ args+=(
+ '(-)-a[show attributes as well]'
+ '(-)-v[show attributes and their values]'
+ '(-)-u[print out sorted unique lines]'
+ '(-)-d-[print out sorted unique lines up to specified depth]:depth'
+ )
+ ;;
+ fo(|rmat))
+ args+=(
+ '(-t --indent-tab -s --indent-spaces -n --noindent)'{-n,--noindent}"[don't indent]"
+ '(-t --indent-tab -s --indent-spaces -n --noindent)'{-t,--indent-tab}'[indent output with tabs]'
+ '(-t --indent-tab -s --indent-spaces -n --noindent)'{-s,--indent-spaces}'[indent output with specified number of spaces]:spaces'
+ '(-R --recover)'{-R,--recover}'[try to recover what is parsable]'
+ '(-D --dropdtd)'{-D,--dropdtd}'[remove the DOCTYPE of the input docs]'
+ '(-C --nocdata)'{-C,--nocdata}'[replace cdata section with text nodes]'
+ '(-N --nsclean)'{-N,--nsclean}'[remove redundant namespace declarations]'
+ '(-e --encode)'{-e,--encode}'[output in the specified encoding]:encoding'
+ '(-H --html)'{-H,--html}'[input is HTML]'
+ )
+ ;;
+ sel(|ect))
+ [[ -n ${${words[2,CURRENT-1]}[(r)-t]} ]] && args+=(
+ \*{-c,--copy-of}'[print copy of XPath expression]:xpath expression'
+ \*{-v,--value-of}'[print value of XPath expression]:xpath expression'
+ \*{-o,--output}'[output string literal]:string'
+ \*{-n,--nl}'[print new line]'
+ \*{-f,--inp-name}'[print input file name (or URL)]'
+ \*{-m,--match}'[match XPath expression]:xpath expression'
+ \*{-v,--var}'[declare a variable]:variable'
+ \*{-i,--if,--elif}'[check condition]:condition'
+ '*--else[check if previous conditions failed]'
+ \*{-e,--elem}'[print out specified element]:element'
+ \*{-b,--break}'[break nesting]'
+ \*{-s,--sort}'[specify sort order]:order:->ordering:xpath expression'
+ )
+ args+=(
+ '(opt)*-t[start query template]'
+ + opt
+ '(-Q --quiet)'{-Q,--quiet}"[don't write anything to standard output]"
+ '(-C --comp)'{-C,--comp}'[display generated XSLT]'
+ '(-R --root)'{-R,--root}'[print root element]'
+ '(-T --text -e --elem)'{-T,--text}'[output is text]'
+ '(-I --indent)'{-I,--indent}'[indent output]'
+ '(-D --xml-decl)'{-D,--xml-decl}"[don't omit xml declaration line]"
+ '(-B --noblanks)'{-B,--noblanks}'[remove insignificant spaces from XML tree]'
+ '(-E --encode)'{-E,--encode}'[output in the specified encoding]:encoding'
+ )
+ ;;
+ tr(|ansform))
+ args+=(
+ '(--embed -E)'{--embed,-E}'[allow applying embedded stylesheet]'
+ '(1 * -)--show-ext[show list of extensions]'
+ '--val[allow validation against DTD or schema]'
+ '--xinclude[do XInclude processing on document input]'
+ '--maxdepth[increase the maximum depth]:val'
+ '--html[input is HTML]'
+ '1:xsl file:_files -g "(#i)*.xsl(|t)(-.)"'
+ '*:xml file:_files'
+ )
+ ;;
+ val(|idate))
+ args+=(
+ '!(-d --dtd -s --xsd -r --relaxng)'{-w,--well-formed}
+ '(-d --dtd -s --xsd -r --relaxng)'{-d,--dtd}'[validate against DTD]:file:_files -g "(#i)*.dtd(-.)"'
+ '(-d --dtd -s --xsd -r --relaxng)'{-s,--xsd}'[validate against XSD schema]:schema file:_files -g "(#i)*.xsd(-.)"'
+ '(-E --embed)'{-E,--embed}'[validate using embedded DTD]'
+ '(-d --dtd -s --xsd -r --relaxng)'{-r,--relaxng}'[validate against schema]:schema file:_files -g "(#i)*.rng(-.)"'
+ '(-e --err)'{-e,--err}'[print verbose error messages on stderr]'
+ '(-S --stop)'{-S,--stop}'[stop on first error]'
+ '(-b --list-bad -g --list-good)'{-b,--list-bad}"[list only files that don't validate]"
+ '(-b --list-bad -g --list-good -q --quiet)'{-g,--list-good}'[list only files that validate]'
+ '(-b --list-bad -g --list-good -q --quiet)'{-q,--quiet}"[don't list files (return result code only)]"
+ '*:file:_files -g "(#i)*.xml(-.)"'
+ )
+ ;;
+ c14n|canonic)
+ args+=(
+ '!(-)--with-comments'
+ '(-)--without-comments[XML file canonicalization without comments]'
+ '(-)--exc-with-comments[exclusive XML file canonicalization with comments]'
+ '(-)--exc-without-comments[exclusive XML file canonicalization without comments]'
+ '2:xpath file:_files'
+ '3:namespace prefix list'
+ )
+ ;;
+ (un|)esc(|ape)) args+=( '1: :_guard "^-*" string' ) ;;
+ ls|list) args+=( '1:path:_directories' ) ;;
+ depyx|p2x) args+=( '1:pyx file:_files' ) ;;
+ esac
+ _arguments -C -A "-*" $args && ret=0
+ case $state in
+ ordering)
+ compset -S ':*' || suf=( -S : )
+ if compset -P 2 '*:'; then
+ _describe -t case-order case-order '(U:upper-first L:lower-first)' && ret=0
+ elif compset -P 1 '*:'; then
+ _describe -t data-type data-type '(N:numeric T:text)' $suf && ret=0
+ else
+ _describe -t order order '(A:ascending D:descending)' $suf && ret=0
+ fi
+ ;;
+ esac
+fi
+
+return ret
Messages sorted by:
Reverse Date,
Date,
Thread,
Author