diff options
| author | tv <tv@krebsco.de> | 2016-06-29 13:46:52 +0200 | 
|---|---|---|
| committer | tv <tv@krebsco.de> | 2016-06-29 13:46:52 +0200 | 
| commit | 41c0c35805ec1708729f73d14650d8ebc94a405b (patch) | |
| tree | 1445c58b032505bf01ac47bf249d3f336741ede3 | |
| parent | 08757d47c480c130d69270855c6c0371f6b7d385 (diff) | |
| -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      '    ) \ | 
