diff --git a/extras/completion/completion.zsh b/extras/completion/completion.zsh index 57f85cd0..839502c3 100644 --- a/extras/completion/completion.zsh +++ b/extras/completion/completion.zsh @@ -1,14 +1,18 @@ -# compdef http +#compdef http # Copyright (c) 2015 Github zsh-users # Based on the initial work of http://github.com/zsh-users +methods=("GET" "POST" "PUT" "DELETE" "HEAD" "OPTIONS" "PATCH" "TRACE" "CONNECT" ) _httpie_params () { local ret=1 expl - + local first_arg=$words[NORMARG] if (( CURRENT == NORMARG )) && [[ $words[NORMARG] != *:* ]]; then # URL _httpie_urls && ret=0 + elif (( CURRENT == NORMARG + 1 )) && [[ ${methods[(ie)$first_arg]} -le ${#methods} ]]; then + # When the first argument is the method, suggest the URL as well. + _httpie_urls && ret=0 elif (( CURRENT > NORMARG )); then # regular param, if we already have a url # ignore all prefix stuff @@ -111,7 +115,6 @@ _arguments -n -C -s \ {--body,-b}'[Print only the response body.]' \ {--verbose,-v}'[Make output more verbose.]' \ '--all[Show any intermediary requests/responses.]' \ - {--history-print,-P}'=[--print for intermediary requests/responses.]:WHAT:' \ {--stream,-S}'[Always stream the response body by line, i.e., behave like `tail -f`.]' \ {--output,-o}'=[Save output to FILE instead of stdout.]:FILE:' \ {--download,-d}'[Download the body to a file instead of printing it to stdout.]' \ diff --git a/extras/completion/templates/completion.zsh.j2 b/extras/completion/templates/completion.zsh.j2 index b78291c9..3dd53a45 100755 --- a/extras/completion/templates/completion.zsh.j2 +++ b/extras/completion/templates/completion.zsh.j2 @@ -1,14 +1,18 @@ -# compdef http +#compdef http # Copyright (c) 2015 Github zsh-users # Based on the initial work of http://github.com/zsh-users +methods=({% for method in methods -%} "{{ method }}" {% endfor -%}) _httpie_params () { local ret=1 expl - + local first_arg=$words[NORMARG] if (( CURRENT == NORMARG )) && [[ $words[NORMARG] != *:* ]]; then # URL _httpie_urls && ret=0 + elif (( CURRENT == NORMARG + 1 )) && [[ ${methods[(ie)$first_arg]} -le ${{ '{#' }}methods} ]]; then + # When the first argument is the method, suggest the URL as well. + _httpie_urls && ret=0 elif (( CURRENT > NORMARG )); then # regular param, if we already have a url # ignore all prefix stuff