aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrest-run43
1 files changed, 24 insertions, 19 deletions
diff --git a/rest-run b/rest-run
index 642a1f9..b0f855b 100755
--- a/rest-run
+++ b/rest-run
@@ -3,6 +3,15 @@
# me=$(basename $0)
me=rest-run
+# [ Define default programs
+
+PAGER="${PAGER:-less -r -f}"
+if command -v moar > /dev/null; then
+ PAGER="moar"
+fi
+
+# ]
+
# [ Helper functions
print-help () {
@@ -183,7 +192,7 @@ fi
case "$rest_response" in
last)
[ $paginate_response = true ] \
- && find "$CACHE_DIR_CONTEXT_RESPONSE" | sort -n | tail -1 | xargs less -r -f \
+ && find "$CACHE_DIR_CONTEXT_RESPONSE" | sort -n | tail -1 | xargs $PAGER \
|| find "$CACHE_DIR_CONTEXT_RESPONSE" | sort -n | tail -1 | xargs cat
exit
;;
@@ -192,7 +201,7 @@ case "$rest_response" in
ranger --choosefile "$tmp_file" "$CACHE_DIR_CONTEXT_RESPONSE"
[[ "$(cat "$tmp_file" 2> /dev/null)" = "" ]] && fail "No file selected"
[ $paginate_response = true ] \
- && cat "$(cat "$tmp_file")" | less -r -f \
+ && cat "$(cat "$tmp_file")" | $PAGER \
|| cat "$(cat "$tmp_file")"
rm "$tmp_file"
exit
@@ -226,20 +235,16 @@ fi
if [ $ignore_body = false ]; then # Send request body
- if [ $paginate_response = true ]; then
cat "$rest_request_file" \
| remove-newlines-from-templates \
| esh - \
- | eval -- http --pretty=all -p HBhbm \
- "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done) > "$rest_response_file"
- less -r -f "$rest_response_file"
- else
- cat "$rest_request_file" \
- | remove-newlines-from-templates \
- | esh - \
- | eval -- http -p HBhbm \
- "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done)
- fi
+ | eval -- http -p HBhbm --pretty=all \
+ "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done) -o "$rest_response_file"
+
+ [ $paginate_response = true ] \
+ && $PAGER "$rest_response_file" \
+ || cat "$rest_response_file"
+
current_request_checksum="$(cat "$rest_request_file" | sha1sum | awk '{print $1}')"
if [[ "${#current_request_checksum}" != "0" && "${#current_request_checksum}" != "1" ]]; then
@@ -250,12 +255,12 @@ if [ $ignore_body = false ]; then # Send request body
else # Send request without body
- if [ $paginate_response = true ]; then
- eval -- http --pretty=all -p HBhbm "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done) > "$rest_response_file"
- less -r -f "$rest_response_file"
- else
- eval -- http -p HBhbm "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done) > "$rest_response_file"
- fi
+ eval -- http --pretty=all -p HBhbm \
+ "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done) -o "$rest_response_file"
+
+ [ $paginate_response = true ] \
+ && $PAGER "$rest_response_file" \
+ || cat "$rest_response_file"
fi