From cf16e785dbc217ed31ca8c933f0ecdf1ccfb3477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Reegn?= Date: Fri, 15 Dec 2023 16:40:52 +0100 Subject: [PATCH] Apply shfmt on scripts --- bin/jq-repl-preview | 22 +++++++++++----------- jq.plugin.zsh | 42 +++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bin/jq-repl-preview b/bin/jq-repl-preview index cd1c994..9339453 100755 --- a/bin/jq-repl-preview +++ b/bin/jq-repl-preview @@ -11,25 +11,25 @@ trap 'rm -f "$out"' EXIT # for colorizing stderr red() { - while read -r line; do - printf "\033[31m%s\033[0m\n" "$line" - done + while read -r line; do + printf "\033[31m%s\033[0m\n" "$line" + done } # prints preview query result to stdout, colorizes stderr to red do_query() { - # JQ_REPL_ARGS has to be unquoted so it's passed as cli args to jq so - # word splitting is desirable here - # shellcheck disable=SC2086 - $JQ_REPL_JQ --color-output ${JQ_REPL_ARGS:-} "$query" "$input_file" + # JQ_REPL_ARGS has to be unquoted so it's passed as cli args to jq so + # word splitting is desirable here + # shellcheck disable=SC2086 + $JQ_REPL_JQ --color-output ${JQ_REPL_ARGS:-} "$query" "$input_file" } 2> >(red) echo "Last successful jq expression: $query" | red >"$out" echo "Last success output:" | red >>"$out" if do_query | tee -a "$out"; then - # save successful query plus the result - mv "$out" "$last_success_file" + # save successful query plus the result + mv "$out" "$last_success_file" else - # print previously saved successful query - cat "$last_success_file" + # print previously saved successful query + cat "$last_success_file" fi diff --git a/jq.plugin.zsh b/jq.plugin.zsh index 35e85f4..2f274aa 100755 --- a/jq.plugin.zsh +++ b/jq.plugin.zsh @@ -1,41 +1,41 @@ if [[ -o zle ]]; then -__lbuffer_strip_trailing_pipe() { + __lbuffer_strip_trailing_pipe() { # Strip a trailing pipe and its surrounding whitespace. sed -E 's/[[:space:]]*\|[[:space:]]*$//' <<<"$LBUFFER" -} + } -__get_query() { + __get_query() { if [ "${JQ_ZSH_PLUGIN_EXPAND_ALIASES:-1}" -eq 1 ]; then - unset 'functions[_jq-plugin-expand]' - functions[_jq-plugin-expand]=$(__lbuffer_strip_trailing_pipe) - (($+functions[_jq-plugin-expand])) && COMMAND=${functions[_jq-plugin-expand]#$'\t'} - # shellcheck disable=SC2086 - jq-repl -- ${COMMAND} - return $? + unset 'functions[_jq-plugin-expand]' + functions[_jq - plugin - expand]=$(__lbuffer_strip_trailing_pipe) + (($ + functions[_jq - plugin - expand])) && COMMAND=${functions[_jq - plugin - expand]#$'\t'} + # shellcheck disable=SC2086 + jq-repl -- ${COMMAND} + return $? else - # shellcheck disable=SC2086 - jq-repl -- $(__lbuffer_strip_trailing_pipe) - return $? + # shellcheck disable=SC2086 + jq-repl -- $(__lbuffer_strip_trailing_pipe) + return $? fi -} + } -jq-complete() { + jq-complete() { local query query="$(__get_query)" local ret=$? if [ -n "$query" ]; then - LBUFFER="$(__lbuffer_strip_trailing_pipe) | ${JQ_REPL_JQ:-jq}" - [[ -z "$JQ_REPL_ARGS" ]] || LBUFFER="${LBUFFER} ${JQ_REPL_ARGS}" - LBUFFER="${LBUFFER} '$query'" + LBUFFER="$(__lbuffer_strip_trailing_pipe) | ${JQ_REPL_JQ:-jq}" + [[ -z "$JQ_REPL_ARGS" ]] || LBUFFER="${LBUFFER} ${JQ_REPL_ARGS}" + LBUFFER="${LBUFFER} '$query'" fi zle reset-prompt return $ret -} + } -zle -N jq-complete -# bind `alt + j` to jq-complete -bindkey '\ej' jq-complete + zle -N jq-complete + # bind `alt + j` to jq-complete + bindkey '\ej' jq-complete fi export PATH=$PATH:${0:A:h}/bin