2 # ------------------------------------------------------------------------------
3 # Copyright (c) 2015 Github zsh-users - http://github.com/zsh-users
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of the zsh-users nor the
14 # names of its contributors may be used to endorse or promote products
15 # derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
21 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # ------------------------------------------------------------------------------
31 # Completion script for httpie 0.7.2 (http://httpie.org)
33 # ------------------------------------------------------------------------------
37 # * Akira Maeda <https://github.com/glidenote>
38 # * Valodim <https://github.com/Valodim>
39 # * Claus Klingberg <https://github.com/cjk>
41 # ------------------------------------------------------------------------------
42 # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
43 # vim: ft=zsh sw=2 ts=2 et
44 # ------------------------------------------------------------------------------
51 if (( CURRENT <= NORMARG+1 )) && [[ $words[NORMARG] != *:* ]] ; then
54 # regular param, if we already have a url
55 elif (( CURRENT > NORMARG )); then
57 # if the suffix is precisely : this is shorthand for a header
58 if [[ -prefix ':' ]]; then
63 # if we are in front of a : (possibly due to the PREFIX move before)
64 if [[ -suffix ':' ]]; then
66 # this is rather buggy with normal tab behavior :\
67 compstate[insert]=menu
68 _wanted http_header expl 'HTTP Header' \
69 compadd -s ':' -S '' -- Content-Type Cookie && return 0
72 # ignore all prefix stuff
73 compset -P '(#b)([^:@=]#)'
76 if compset -P '='; then
77 _message "$name data field value"
78 elif compset -P '@'; then
80 elif compset -P ':=@'; then
82 elif compset -P ':='; then
83 _message "$name raw json data"
84 elif compset -P '=='; then
85 _message "$name url parameter value"
86 elif compset -P ':'; then
87 _message "$name header content"
93 '==:request parameter'
96 '\:=@:raw json field file path'
98 _describe -t httpparams "parameter types" ops -Q -S ''
105 # first arg may be a request method
106 (( CURRENT == NORMARG )) &&
107 _wanted http_method expl 'Request Method' \
108 compadd GET POST PUT DELETE HEAD OPTIONS TRACE CONNECT PATCH LINK UNLINK && ret=0
118 if ! [[ -prefix [-+.a-z0-9]#:// ]]; then
120 compset -S '[^:/]*' && compstate[to_end]=''
121 _wanted url-schemas expl 'URL schema' compadd -S '' http:// https:// && ret=0
130 _httpie_printflags () {
134 # not sure why this is necessary, but it will complete "-pH" style without it
135 [[ $IPREFIX == "-p" ]] && IPREFIX+=" "
137 compset -P '(#b)([a-zA-Z]#)'
140 [[ $match[1] != *H* ]] && flags+=( "H:request headers" )
141 [[ $match[1] != *B* ]] && flags+=( "B:request body" )
142 [[ $match[1] != *h* ]] && flags+=( "h:response headers" )
143 [[ $match[1] != *b* ]] && flags+=( "b:response body" )
145 _describe -t printflags "print flags" flags -S '' && ret=0
153 _arguments -n -C -s \
154 '(-j --json -f)'{-j,--json}'[Data items from the command line are serialized as a JSON object.]' \
155 '(-f --form -j)'{-f,--form}'[Data items from the command line are serialized as form fields.]' \
156 '--pretty=[Controls output processing.]:output format:(all colors format none)' \
157 '(-s --style)'{-s,--style}'=[Output coloring style]:STYLE:(autumn borland bw colorful default emacs friendly fruity manni monokai murphy native pastie perldoc ttr solarized tango trac vim vs)' \
158 '(-p --print)'{-p,--print}'=[String specifying what the output should contain]:print flags:_httpie_printflags' \
159 '(-v --verbose)'{-v,--verbose}'[Print the whole request as well as the response.]' \
160 '(-p -h --headers)'{-h,--headers}'[Print only the response headers.]' \
161 '(-p -b --body)'{-b,--body}'[Print only the response body.]' \
162 '(-S --stream)'{-S,--stream}'[Always stream the output by line, i.e., behave like `tail -f`.]' \
163 '(-o --output)'{-o,--output}'=[Save output to FILE.]:output file:_files' \
164 '(-d --download)'{-d,--download}'=[Do not print the response body to stdout.]' \
165 '(-c --continue)'{-c,--continue}'[Resume an interrupted download.]' \
166 '(--session-read-only)--session=[Create, or reuse and update a session.]:session name (or path)' \
167 '(--session)--session-read-only=[Create or read a session without updating it form the request/response exchange.]:session name (or path)' \
168 '(-a --auth)'{-a,--auth}'=[If only the username is provided (-a username)]:USER\:PASS' \
169 '--auth-type=[The authentication mechanism to be used. Defaults to "basic".]:AUTH-TYPE:(basic digest)' \
170 '--proxy=[String mapping protocol to the URL of the proxy.]:PROXY' \
171 '--follow[Allow full redirects.]' \
172 "--verify=[Enable or disable verification of ssl certificates.]:verify certificate:(yes no)" \
173 '--allow-redirects[Set this flag if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)]' \
174 '--timeout=[Float describes the timeout of the request (Use socket.setdefaulttimeout() as fallback).]:timeout (seconds)' \
175 '--check-status[This flag instructs HTTPie to also check the HTTP status code and exit with an error if the status indicates one.]' \
176 '--ignore-stdin[Do not attempt to read stdin.]' \
177 '(- *)--help[show help message.]' \
178 "(- *)--version[show program's version number and exit.]" \
179 '--traceback[Prints exception traceback should one occur.]' \
180 '--debug[Prints exception traceback should one occur and other information useful for debugging HTTPie itself.]' \
181 '*:args:_httpie_params' && return 0