Source: https://github.com/zsh-users/zsh-completions/blob/master/src/_httpie Related: #7308master
parent
069df888b0
commit
ab14068368
3 changed files with 194 additions and 37 deletions
@ -1,6 +1,15 @@ |
||||
## HTTPie |
||||
**Maintainer:** [lululau](https://github.com/lululau) |
||||
# HTTPie plugin |
||||
|
||||
This plugin adds completion for [HTTPie](https://httpie.org), a command line HTTP |
||||
client, a friendlier cURL replacement. |
||||
|
||||
To use it, add `httpie` to the plugins array in your zshrc file: |
||||
|
||||
This plugin adds completion for HTTPie, which is a command line HTTP client, a user-friendly cURL replacement. |
||||
```zsh |
||||
plugins=(... httpie) |
||||
``` |
||||
|
||||
[HTTPie Homepage](https://httpie.org) |
||||
It uses completion from [zsh-completions](https://github.com/zsh-users/zsh-completions). |
||||
|
||||
|
||||
**Maintainer:** [lululau](https://github.com/lululau) |
||||
|
||||
@ -0,0 +1,181 @@ |
||||
#compdef http |
||||
# ------------------------------------------------------------------------------ |
||||
# Copyright (c) 2015 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 httpie 0.7.2 (http://httpie.org) |
||||
# |
||||
# ------------------------------------------------------------------------------ |
||||
# Authors |
||||
# ------- |
||||
# |
||||
# * Akira Maeda <https://github.com/glidenote> |
||||
# * Valodim <https://github.com/Valodim> |
||||
# * Claus Klingberg <https://github.com/cjk> |
||||
# |
||||
# ------------------------------------------------------------------------------ |
||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- |
||||
# vim: ft=zsh sw=2 ts=2 et |
||||
# ------------------------------------------------------------------------------ |
||||
|
||||
_httpie_params () { |
||||
|
||||
local ret=1 expl |
||||
|
||||
# or a url |
||||
if (( CURRENT <= NORMARG+1 )) && [[ $words[NORMARG] != *:* ]] ; then |
||||
_httpie_urls && ret=0 |
||||
|
||||
# regular param, if we already have a url |
||||
elif (( CURRENT > NORMARG )); then |
||||
|
||||
# if the suffix is precisely : this is shorthand for a header |
||||
if [[ -prefix ':' ]]; then |
||||
PREFIX= |
||||
SUFFIX=: |
||||
fi |
||||
|
||||
# if we are in front of a : (possibly due to the PREFIX move before) |
||||
if [[ -suffix ':' ]]; then |
||||
|
||||
# this is rather buggy with normal tab behavior :\ |
||||
compstate[insert]=menu |
||||
_wanted http_header expl 'HTTP Header' \ |
||||
compadd -s ':' -S '' -- Content-Type Cookie && return 0 |
||||
fi |
||||
|
||||
# ignore all prefix stuff |
||||
compset -P '(#b)([^:@=]#)' |
||||
local name=$match[1] |
||||
|
||||
if compset -P '='; then |
||||
_message "$name data field value" |
||||
elif compset -P '@'; then |
||||
_files |
||||
elif compset -P ':=@'; then |
||||
_files |
||||
elif compset -P ':='; then |
||||
_message "$name raw json data" |
||||
elif compset -P '=='; then |
||||
_message "$name url parameter value" |
||||
elif compset -P ':'; then |
||||
_message "$name header content" |
||||
else |
||||
typeset -a ops |
||||
ops=( |
||||
'=:data field' |
||||
'\::header' |
||||
'==:request parameter' |
||||
'@:data file field' |
||||
'\:=:raw json field' |
||||
'\:=@:raw json field file path' |
||||
) |
||||
_describe -t httpparams "parameter types" ops -Q -S '' |
||||
fi |
||||
|
||||
ret=0 |
||||
|
||||
fi |
||||
|
||||
# first arg may be a request method |
||||
(( CURRENT == NORMARG )) && |
||||
_wanted http_method expl 'Request Method' \ |
||||
compadd GET POST PUT DELETE HEAD OPTIONS TRACE CONNECT PATCH LINK UNLINK && ret=0 |
||||
|
||||
return $ret |
||||
|
||||
} |
||||
|
||||
_httpie_urls() { |
||||
|
||||
local ret=1 |
||||
|
||||
if ! [[ -prefix [-+.a-z0-9]#:// ]]; then |
||||
local expl |
||||
compset -S '[^:/]*' && compstate[to_end]='' |
||||
_wanted url-schemas expl 'URL schema' compadd -S '' http:// https:// && ret=0 |
||||
else |
||||
_urls && ret=0 |
||||
fi |
||||
|
||||
return $ret |
||||
|
||||
} |
||||
|
||||
_httpie_printflags () { |
||||
|
||||
local ret=1 |
||||
|
||||
# not sure why this is necessary, but it will complete "-pH" style without it |
||||
[[ $IPREFIX == "-p" ]] && IPREFIX+=" " |
||||
|
||||
compset -P '(#b)([a-zA-Z]#)' |
||||
|
||||
local -a flags |
||||
[[ $match[1] != *H* ]] && flags+=( "H:request headers" ) |
||||
[[ $match[1] != *B* ]] && flags+=( "B:request body" ) |
||||
[[ $match[1] != *h* ]] && flags+=( "h:response headers" ) |
||||
[[ $match[1] != *b* ]] && flags+=( "b:response body" ) |
||||
|
||||
_describe -t printflags "print flags" flags -S '' && ret=0 |
||||
|
||||
return $ret |
||||
|
||||
} |
||||
|
||||
integer NORMARG |
||||
|
||||
_arguments -n -C -s \ |
||||
'(-j --json -f)'{-j,--json}'[Data items from the command line are serialized as a JSON object.]' \ |
||||
'(-f --form -j)'{-f,--form}'[Data items from the command line are serialized as form fields.]' \ |
||||
'--pretty=[Controls output processing.]:output format:(all colors format none)' \ |
||||
'(-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)' \ |
||||
'(-p --print)'{-p,--print}'=[String specifying what the output should contain]:print flags:_httpie_printflags' \ |
||||
'(-v --verbose)'{-v,--verbose}'[Print the whole request as well as the response.]' \ |
||||
'(-p -h --headers)'{-h,--headers}'[Print only the response headers.]' \ |
||||
'(-p -b --body)'{-b,--body}'[Print only the response body.]' \ |
||||
'(-S --stream)'{-S,--stream}'[Always stream the output by line, i.e., behave like `tail -f`.]' \ |
||||
'(-o --output)'{-o,--output}'=[Save output to FILE.]:output file:_files' \ |
||||
'(-d --download)'{-d,--download}'=[Do not print the response body to stdout.]' \ |
||||
'(-c --continue)'{-c,--continue}'[Resume an interrupted download.]' \ |
||||
'(--session-read-only)--session=[Create, or reuse and update a session.]:session name (or path)' \ |
||||
'(--session)--session-read-only=[Create or read a session without updating it form the request/response exchange.]:session name (or path)' \ |
||||
'(-a --auth)'{-a,--auth}'=[If only the username is provided (-a username)]:USER\:PASS' \ |
||||
'--auth-type=[The authentication mechanism to be used. Defaults to "basic".]:AUTH-TYPE:(basic digest)' \ |
||||
'--proxy=[String mapping protocol to the URL of the proxy.]:PROXY' \ |
||||
'--follow[Allow full redirects.]' \ |
||||
"--verify=[Enable or disable verification of ssl certificates.]:verify certificate:(yes no)" \ |
||||
'--allow-redirects[Set this flag if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)]' \ |
||||
'--timeout=[Float describes the timeout of the request (Use socket.setdefaulttimeout() as fallback).]:timeout (seconds)' \ |
||||
'--check-status[This flag instructs HTTPie to also check the HTTP status code and exit with an error if the status indicates one.]' \ |
||||
'--ignore-stdin[Do not attempt to read stdin.]' \ |
||||
'(- *)--help[show help message.]' \ |
||||
"(- *)--version[show program's version number and exit.]" \ |
||||
'--traceback[Prints exception traceback should one occur.]' \ |
||||
'--debug[Prints exception traceback should one occur and other information useful for debugging HTTPie itself.]' \ |
||||
'*:args:_httpie_params' && return 0 |
||||
@ -1,33 +0,0 @@ |
||||
function _httpie_completion() { |
||||
_arguments -C \ |
||||
'(- 1 *)--version[display version information]' \ |
||||
'(-j|--json)'{-j,--json}'[(default) Data items from the command line are serialized as a JSON object]' \ |
||||
'(-f|--form)'{-f,--form}'[Data items from the command line are serialized as form fields]' \ |
||||
'(--pretty)--pretty[<all,colors,format,none> Controls output processing]:options' \ |
||||
'(-s|--style)'{-s,--style}'[Output coloring style]' \ |
||||
'(-p|--print)'{-p,--print}'[String specifying what the output should contain: H(request headers), B(request body), h(response headers), b(response body)]' \ |
||||
'(-v|--verbose)'{-v,--verbose}'[Print the whole request as well as the response. Shortcut for --print=HBbh.]' \ |
||||
'(-h|--headers)'{-h,--headers}'[Print only the response headers. Shortcut for --print=h]' \ |
||||
'(-b|--body)'{-b,--body}'[Print only the response body. Shortcut for --print=b]' \ |
||||
'(-S|--stream)'{-S,--stream}'[Always stream the output by line, i.e., behave like `tail -f'"'"']' \ |
||||
'(-o|--output)'{-o,--output}'[Save output to FILE]:file:_files' \ |
||||
'(-d|--download)'{-d,--download}'[Do not print the response body to stdout. Rather, download it and store it in a file. The filename is guessed unless specified with --output filename. This action is similar to the default behaviour of wget.]' \ |
||||
'(-c|--continue)'{-c,--continue}'[Resume an interrupted download. Note that the --output option needs to be specified as well.]' \ |
||||
'(--session)--session[Create, or reuse and update a session. Within a session, custom headers, auth credential, as well as any cookies sent by the server persist between requests]:file:_files' \ |
||||
'(--session-read-only)--session-read-only[Create or read a session without updating it form the request/response exchange]:file:_files' \ |
||||
'(-a|--auth)'{-a,--auth}'[<USER:PASS> If only the username is provided (-a username), HTTPie will prompt for the password]' \ |
||||
'(--auth-type)--auth-type[<basic, digest> The authentication mechanism to be used. Defaults to "basic".]' \ |
||||
'(--proxy)--proxy[<PROTOCOL:PROXY_URL> String mapping protocol to the URL of the proxy]' \ |
||||
'(--follow)--follow[Set this flag if full redirects are allowed (e.g. re-POST-ing of data at new Location).]' \ |
||||
'(--verify)--verify[<VERIFY> Set to "no" to skip checking the host'"'"'s SSL certificate. You can also pass the path to a CA_BUNDLE file for private certs. You can also set the REQUESTS_CA_BUNDLE environment variable. Defaults to "yes".]' \ |
||||
'(--timeout)--timeout[<SECONDS> The connection timeout of the request in seconds. The default value is 30 seconds]' \ |
||||
'(--check-status)--check-status[By default, HTTPie exits with 0 when no network or other fatal errors occur. This flag instructs HTTPie to also check the HTTP status code and exit with an error if the status indicates one.]' \ |
||||
'(--ignore-stdin)--ignore-stdin[Do not attempt to read stdin]' \ |
||||
'(--help)--help[Show this help message and exit]' \ |
||||
'(--traceback)--traceback[Prints exception traceback should one occur]' \ |
||||
'(--debug)--debug[Prints exception traceback should one occur, and also other information that is useful for debugging HTTPie itself and for reporting bugs]' \ |
||||
'1: :->cmds' \ |
||||
'*: :->args' && ret=0 |
||||
} |
||||
|
||||
compdef _httpie_completion http |
||||
Loading…
Reference in new issue