From fbe8f8d12ede9762fceb15b9944b69a4ee6331eb Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 1 Oct 2015 02:40:53 +0200 Subject: render string results by default As it turns out, -r was used more often than not. So making it the default is the only sane choice. Also for more interactive fun.^_^ --- get | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/get b/get index 4fe8939..ef2f636 100755 --- a/get +++ b/get @@ -17,9 +17,10 @@ # # -p Pretty-print output. (Only effectiv in conjunction with -j.) # -# -r If result looks is a string, then it will be written directly to -# standard output rather than being formatted as JSON or Nix string -# with quotes. Refs jq(1)'s --raw-output. +# -r Disable the default filter and produce raw output. Normally, when +# the result looks like a JSON or Nix string, i.e. begins with a double +# quote, then the string itself gets printed. +# Refs jq(1)'s --raw-output. # # -s Recursively evaluate list elements and attributes. # Refs nix-instantiate(1)'s --strict. @@ -39,7 +40,14 @@ has_sopt() { echo "$args" | grep -q '\(^\|\s\)-[a-z]*'"$1"'[a-z]*\(\s\|$\)' } -filter() { cat; } +filter() { + set -- "$(cat)" + if test "${1:0:1}" = \"; then + echo "$1" | jq -e -r . + else + echo "$1" + fi +} if has_sopt j; then json=1 @@ -57,7 +65,7 @@ if has_sopt p && has_sopt j; then fi if has_sopt r; then - raw_output=1 + filter() { cat; } fi if has_sopt s; then @@ -93,10 +101,4 @@ result=$(nix-instantiate \ --argstr current-user-name "$LOGNAME" \ ) -case ${raw_output-0} in 1) - case ${result:0:1} in \") - result=$(echo "$result" | jq -e -r .) - esac -esac - echo "$result" | filter -- cgit v1.2.3