summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2016-06-29 13:46:52 +0200
committertv <tv@krebsco.de>2016-06-29 13:46:52 +0200
commit41c0c35805ec1708729f73d14650d8ebc94a405b (patch)
tree1445c58b032505bf01ac47bf249d3f336741ede3
parent08757d47c480c130d69270855c6c0371f6b7d385 (diff)
enable listing of arbitrary attrsets when using -lHEADni/mastercd/mastercd/HEADmaster
-rwxr-xr-xget18
1 files changed, 13 insertions, 5 deletions
diff --git a/get b/get
index 2ed2fe6..d452d9a 100755
--- a/get
+++ b/get
@@ -13,7 +13,8 @@
#
# -j Format output as JSON. Implies -s.
#
-# -l List attrNames, one per line.
+# -l List attrNames, one per line. If used in conjunction with -j, then
+# the list will be output as JSON value.
#
# -p Pretty-print output. (Only effectiv in conjunction with -j.)
#
@@ -55,9 +56,13 @@ if has_sopt j; then
fi
if has_sopt l; then
- unset json
- unset strict
- filter() { sed 's/\({ \)\?\(\S\+\) = <CODE>; }\?/\2\n/g' | grep .; }
+ query='-E builtins.attrNames((import(./.)).&)'
+ if ! has_sopt j; then
+ json=1
+ filter() { jq -r .[]; }
+ fi
+else
+ query='-A &'
fi
if has_sopt p && has_sopt j; then
@@ -83,6 +88,9 @@ if x=$(nix-instantiate --json --eval -A NIX_PATH 2>/dev/null); then
unset x
fi
+# Quote slashes so we can use query as replacement string for sed's s///.
+query=$(echo "$query" | sed 's:/:\\&:')
+
result=$(nix-instantiate \
${json+--json} \
${show_trace+--show-trace} \
@@ -92,7 +100,7 @@ result=$(nix-instantiate \
for i; do
echo "$i"
done | sed -n '
- s/^[A-Za-z_][0-9A-Za-z_"./-]*$/--attr &/p
+ s/^[A-Za-z_][0-9A-Za-z_"./-]*$/'"$query"'/p
s/^\([0-9A-Za-z-]\+\)=\([.0-9A-Za-z-]*\)$/--argstr \1 \2/p
'
) \