diff options
-rw-r--r-- | completions/zsh/_rest-run | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/completions/zsh/_rest-run b/completions/zsh/_rest-run index dfa6873..003caaf 100644 --- a/completions/zsh/_rest-run +++ b/completions/zsh/_rest-run @@ -6,17 +6,31 @@ function __debug { echo "$1" >> /tmp/_rest-run.log } +function _rest-run_read_domain () { + local ARG="${words[2]}" + + if [ ${#ARG} -lt 7 ]; then + ARG="${words[3]}" + fi + + echo "$ARG" | sed 's/[a-z]*:\/\///g' | sed 's/\/.*//g' | sed 's/\?.*//g' +} + function _rest-run { local line local -a args args+=( '1:*:(POST GET PUT PATCH DELETE)' - '--no-edit[Skip request body edit]' - '--body[Body options]: :_rest-run_body_opts' - '--response[Response options]: :_rest-run_response_opts' + '-ne[Skip request body edit]' + '-b[Body options]: :_rest-run_body_opts' + '-r[Response options]: :_rest-run_response_opts' + '-e[Extract request data]: :_rest-run_extract_opts' + '-rr[Read response file]: :_rest-run_select_response_opts' '*-h[HTTP header]' - '--paginate[Paginate request response]' + '-p[Paginate request response]' + '--no-color[Disable ANSI color scape codes (default when output is being piped)]' + '--color[Enable ANSI color scape codes]' ) _arguments -C $args @@ -27,9 +41,9 @@ function _rest-run_body_opts { _descriptions=( 'default -- create a request body using the default editor' - 'last -- use the last request' + 'last -- use the last request' 'history -- pick from the request history' - 'stdin -- reads from piped input' + 'stdin -- reads from piped input' ) _values=( @@ -47,7 +61,7 @@ function _rest-run_response_opts { _descriptions=( 'default -- store the request on cache' - 'last -- read last request, skip request' + 'last -- read last request, skip request' 'history -- pick from the response history, skip request' ) @@ -60,6 +74,39 @@ function _rest-run_response_opts { compadd -d _descriptions -a _values } +function _rest-run_extract_opts { + local -a _descriptions _values + + _descriptions=( + 'default -- whole request and response, headers and body' + 'body -- only response body (default when output is piped to another process)' + 'headers -- only response headers' + 'rbody -- only request body' + 'rheaders -- only request headers' + ) + + _values=( + 'default' + 'body' + 'headers' + 'rbody' + 'rheaders' + ) + + compadd -d _descriptions -a _values +} + +function _rest-run_select_response_opts { + local domain="$(_rest-run_read_domain)" + local -a _values + + for f in $(find $HOME/.cache/rest-run/$domain -type f -iname '*response*'); do + _values+=("$(echo "$f" | sed 's/^.*\/\.cache\/rest-run\///g')") + done + + compadd -a _values +} + if [ "$funcstack[1]" = "_rest-run" ]; then _rest-run fi |