_httpie 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #compdef http
  2. # ------------------------------------------------------------------------------
  3. # Copyright (c) 2015 Github zsh-users - http://github.com/zsh-users
  4. # All rights reserved.
  5. #
  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.
  16. #
  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. # ------------------------------------------------------------------------------
  28. # Description
  29. # -----------
  30. #
  31. # Completion script for httpie 0.7.2 (http://httpie.org)
  32. #
  33. # ------------------------------------------------------------------------------
  34. # Authors
  35. # -------
  36. #
  37. # * Akira Maeda <https://github.com/glidenote>
  38. # * Valodim <https://github.com/Valodim>
  39. # * Claus Klingberg <https://github.com/cjk>
  40. #
  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. # ------------------------------------------------------------------------------
  45. _httpie_params () {
  46. local ret=1 expl
  47. # or a url
  48. if (( CURRENT <= NORMARG+1 )) && [[ $words[NORMARG] != *:* ]] ; then
  49. _httpie_urls && ret=0
  50. # regular param, if we already have a url
  51. elif (( CURRENT > NORMARG )); then
  52. # if the suffix is precisely : this is shorthand for a header
  53. if [[ -prefix ':' ]]; then
  54. PREFIX=
  55. SUFFIX=:
  56. fi
  57. # if we are in front of a : (possibly due to the PREFIX move before)
  58. if [[ -suffix ':' ]]; then
  59. # this is rather buggy with normal tab behavior :\
  60. compstate[insert]=menu
  61. _wanted http_header expl 'HTTP Header' \
  62. compadd -s ':' -S '' -- Content-Type Cookie && return 0
  63. fi
  64. # ignore all prefix stuff
  65. compset -P '(#b)([^:@=]#)'
  66. local name=$match[1]
  67. if compset -P '='; then
  68. _message "$name data field value"
  69. elif compset -P '@'; then
  70. _files
  71. elif compset -P ':=@'; then
  72. _files
  73. elif compset -P ':='; then
  74. _message "$name raw json data"
  75. elif compset -P '=='; then
  76. _message "$name url parameter value"
  77. elif compset -P ':'; then
  78. _message "$name header content"
  79. else
  80. typeset -a ops
  81. ops=(
  82. '=:data field'
  83. '\::header'
  84. '==:request parameter'
  85. '@:data file field'
  86. '\:=:raw json field'
  87. '\:=@:raw json field file path'
  88. )
  89. _describe -t httpparams "parameter types" ops -Q -S ''
  90. fi
  91. ret=0
  92. fi
  93. # first arg may be a request method
  94. (( CURRENT == NORMARG )) &&
  95. _wanted http_method expl 'Request Method' \
  96. compadd GET POST PUT DELETE HEAD OPTIONS TRACE CONNECT PATCH LINK UNLINK && ret=0
  97. return $ret
  98. }
  99. _httpie_urls() {
  100. local ret=1
  101. if ! [[ -prefix [-+.a-z0-9]#:// ]]; then
  102. local expl
  103. compset -S '[^:/]*' && compstate[to_end]=''
  104. _wanted url-schemas expl 'URL schema' compadd -S '' http:// https:// && ret=0
  105. else
  106. _urls && ret=0
  107. fi
  108. return $ret
  109. }
  110. _httpie_printflags () {
  111. local ret=1
  112. # not sure why this is necessary, but it will complete "-pH" style without it
  113. [[ $IPREFIX == "-p" ]] && IPREFIX+=" "
  114. compset -P '(#b)([a-zA-Z]#)'
  115. local -a flags
  116. [[ $match[1] != *H* ]] && flags+=( "H:request headers" )
  117. [[ $match[1] != *B* ]] && flags+=( "B:request body" )
  118. [[ $match[1] != *h* ]] && flags+=( "h:response headers" )
  119. [[ $match[1] != *b* ]] && flags+=( "b:response body" )
  120. _describe -t printflags "print flags" flags -S '' && ret=0
  121. return $ret
  122. }
  123. integer NORMARG
  124. _arguments -n -C -s \
  125. '(-j --json -f)'{-j,--json}'[Data items from the command line are serialized as a JSON object.]' \
  126. '(-f --form -j)'{-f,--form}'[Data items from the command line are serialized as form fields.]' \
  127. '--pretty=[Controls output processing.]:output format:(all colors format none)' \
  128. '(-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)' \
  129. '(-p --print)'{-p,--print}'=[String specifying what the output should contain]:print flags:_httpie_printflags' \
  130. '(-v --verbose)'{-v,--verbose}'[Print the whole request as well as the response.]' \
  131. '(-p -h --headers)'{-h,--headers}'[Print only the response headers.]' \
  132. '(-p -b --body)'{-b,--body}'[Print only the response body.]' \
  133. '(-S --stream)'{-S,--stream}'[Always stream the output by line, i.e., behave like `tail -f`.]' \
  134. '(-o --output)'{-o,--output}'=[Save output to FILE.]:output file:_files' \
  135. '(-d --download)'{-d,--download}'=[Do not print the response body to stdout.]' \
  136. '(-c --continue)'{-c,--continue}'[Resume an interrupted download.]' \
  137. '(--session-read-only)--session=[Create, or reuse and update a session.]:session name (or path)' \
  138. '(--session)--session-read-only=[Create or read a session without updating it form the request/response exchange.]:session name (or path)' \
  139. '(-a --auth)'{-a,--auth}'=[If only the username is provided (-a username)]:USER\:PASS' \
  140. '--auth-type=[The authentication mechanism to be used. Defaults to "basic".]:AUTH-TYPE:(basic digest)' \
  141. '--proxy=[String mapping protocol to the URL of the proxy.]:PROXY' \
  142. '--follow[Allow full redirects.]' \
  143. "--verify=[Enable or disable verification of ssl certificates.]:verify certificate:(yes no)" \
  144. '--allow-redirects[Set this flag if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)]' \
  145. '--timeout=[Float describes the timeout of the request (Use socket.setdefaulttimeout() as fallback).]:timeout (seconds)' \
  146. '--check-status[This flag instructs HTTPie to also check the HTTP status code and exit with an error if the status indicates one.]' \
  147. '--ignore-stdin[Do not attempt to read stdin.]' \
  148. '(- *)--help[show help message.]' \
  149. "(- *)--version[show program's version number and exit.]" \
  150. '--traceback[Prints exception traceback should one occur.]' \
  151. '--debug[Prints exception traceback should one occur and other information useful for debugging HTTPie itself.]' \
  152. '*:args:_httpie_params' && return 0