aboutsummaryrefslogtreecommitdiffstats
path: root/src/_httpie
diff options
context:
space:
mode:
authorShohei YOSHIDA <syohex@gmail.com>2022-11-07 16:41:39 +0900
committerShohei YOSHIDA <syohex@gmail.com>2022-11-07 16:41:39 +0900
commitbfc56a2e4cd4a02c324e6fcee99bed9d4e947136 (patch)
treef8bb7d753fb861637841b4481c1d4f3ea7e317ff /src/_httpie
parentMerge pull request #891 from max-ae/httpie-https (diff)
downloadzsh-completions-bfc56a2e4cd4a02c324e6fcee99bed9d4e947136.tar
zsh-completions-bfc56a2e4cd4a02c324e6fcee99bed9d4e947136.tar.gz
zsh-completions-bfc56a2e4cd4a02c324e6fcee99bed9d4e947136.tar.bz2
zsh-completions-bfc56a2e4cd4a02c324e6fcee99bed9d4e947136.tar.lz
zsh-completions-bfc56a2e4cd4a02c324e6fcee99bed9d4e947136.tar.xz
zsh-completions-bfc56a2e4cd4a02c324e6fcee99bed9d4e947136.tar.zst
zsh-completions-bfc56a2e4cd4a02c324e6fcee99bed9d4e947136.zip
Update httpie completion and reformat code
- Reformat - Remove deprecated options - Add missing candidates of `--style` and `--auth-type`
Diffstat (limited to 'src/_httpie')
-rw-r--r--src/_httpie146
1 files changed, 76 insertions, 70 deletions
diff --git a/src/_httpie b/src/_httpie
index deb4b6d..015e5c0 100644
--- a/src/_httpie
+++ b/src/_httpie
@@ -41,76 +41,72 @@
#
# ------------------------------------------------------------------------------
-_httpie_params () {
+_httpie_params() {
+ local ret=1 expl
- local ret=1 expl
-
- # or a url
- if (( CURRENT <= NORMARG+1 )) && [[ $words[NORMARG] != *:* ]] ; then
- _httpie_urls && ret=0
+ # 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
+ elif (( CURRENT > NORMARG )); then
- # if we are in front of a : (possibly due to the PREFIX move before)
- if [[ -suffix ':' ]]; then
+ # if the suffix is precisely : this is shorthand for a header
+ if [[ -prefix ':' ]]; then
+ PREFIX=
+ SUFFIX=:
+ fi
- # 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
+ # 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]
+ # 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
+ 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
+ ret=0
- fi
+ fi
- # first arg may be a request method
- (( CURRENT == NORMARG )) &&
- _wanted http_method expl 'Request Method' \
+ # 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
-
+ return $ret
}
_httpie_urls() {
-
local ret=1
if ! [[ -prefix [-+.a-z0-9]#:// ]]; then
@@ -125,25 +121,36 @@ _httpie_urls() {
}
-_httpie_printflags () {
+_httpie_printflags() {
+ local ret=1
- local ret=1
+ # not sure why this is necessary, but it will complete "-pH" style without it
+ [[ $IPREFIX == "-p" ]] && IPREFIX+=" "
- # not sure why this is necessary, but it will complete "-pH" style without it
- [[ $IPREFIX == "-p" ]] && IPREFIX+=" "
+ compset -P '(#b)([a-zA-Z]#)'
- 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" )
- 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
- _describe -t printflags "print flags" flags -S '' && ret=0
+ return $ret
+}
- return $ret
+_httpie_styles() {
+ local -a styles=(abap algol algol_nu arduino auto autumn borland bw
+ colorful default dracula emacs friendly
+ friendly_grayscale fruity gruvbox-dark gruvbox-light
+ igor inkpot lilypond lovelace manni material monokai
+ murphy native one-dark paraiso-dark paraiso-light
+ pastie perldoc pie pie-dark pie-light rainbow_dash
+ rrt sas solarized solarized-dark solarized-light stata
+ stata-dark stata-light tango trac vim vs xcode zenburn)
+ _describe -t styles 'style' styles
}
integer NORMARG
@@ -156,7 +163,7 @@ _arguments -n -C -s \
'--raw=[This option allows you to pass raw request data without extra processing]' \
'(-x --compress)'{-x,--compress}'[Content compressed with Deflate algorithm]' \
'--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)' \
+ '(-s --style)'{-s,--style}'=[Output coloring style]:STYLE:_httpie_styles' \
'--unsorted[Disables all sorting while formatting output]' \
'--sorted[Re-enables all sorting options while formatting output]' \
'--response-charset=[Override the response encoding for terminal display purposes]' \
@@ -168,7 +175,6 @@ _arguments -n -C -s \
'(-p -m --meta)'{-m,--meta}'[Print only the response metadata]' \
'(-p -b --body)'{-b,--body}'[Print only the response body.]' \
'--all[By default, only the final request/response is shown]' \
- '(--P --history-print)'{-P,--history-print}'=[The same as --print but applies only to intermediary requests/response]:print flags:_httpie_printflags' \
'(-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.]' \
@@ -177,7 +183,7 @@ _arguments -n -C -s \
'(--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)' \
+ '--auth-type=[The authentication mechanism to be used. Defaults to "basic".]:AUTH-TYPE:(basic digest bearer)' \
'--ignore-netrc[Ignore credentials from .netrc]' \
'--offline[Build the request and print it but do not actually send it]' \
'--proxy=[String mapping protocol to the URL of the proxy.]:PROXY' \