summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-10-01 02:40:53 +0200
committertv <tv@shackspace.de>2015-10-01 02:40:53 +0200
commitfbe8f8d12ede9762fceb15b9944b69a4ee6331eb (patch)
treef1d47152a940563a91acbeec13a2668c6954cb81
parent9801ebe6f527b9505799ff423c427c03694d85de (diff)
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.^_^
-rwxr-xr-xget24
1 files 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