Update httpie completion and reformat code

- Reformat
- Remove deprecated options
- Add missing candidates of `--style` and `--auth-type`
This commit is contained in:
Shohei YOSHIDA 2022-11-07 16:41:39 +09:00
parent 14da57e8e2
commit bfc56a2e4c
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 80 additions and 74 deletions

View File

@ -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
# 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
elif (( CURRENT > NORMARG )); then
# if the suffix is precisely : this is shorthand for a header
if [[ -prefix ':' ]]; then
PREFIX=
SUFFIX=:
fi
# first arg may be a request method
(( CURRENT == NORMARG )) &&
_wanted http_method expl 'Request Method' \
# 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
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' \