diff options
-rwxr-xr-x | get | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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 ' ) \ |