diff options
-rwxr-xr-x | get | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -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 |