aboutsummaryrefslogtreecommitdiff
path: root/completions/zsh
diff options
context:
space:
mode:
authorJefferson Julio <[email protected]>2022-05-15 18:38:00 -0300
committerJefferson Julio <[email protected]>2022-05-15 18:38:00 -0300
commitabf68c8495edd9b99789ac6dd97e536fa0fe9234 (patch)
treebf47df4f4050b02a02d7dec4707bd5c753d4ebe5 /completions/zsh
parentc03c8444ee71433c70e7fadf19bc1fd78fe2f78c (diff)
downloadrest-run-abf68c8495edd9b99789ac6dd97e536fa0fe9234.tar.bz2
rest-run-abf68c8495edd9b99789ac6dd97e536fa0fe9234.zip
Update ZSH completions.
Diffstat (limited to 'completions/zsh')
-rw-r--r--completions/zsh/_rest-run61
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