use direnv show_dump to extract direnv watches

This commit is contained in:
Jörg Thalheim 2023-11-26 13:15:37 +01:00
parent 433948e9ad
commit 4248f7735b
2 changed files with 4 additions and 13 deletions

View file

@ -9,7 +9,6 @@ stdenv.mkDerivation {
sed -i "2iNIX_BIN_PREFIX=${nix}/bin/" direnvrc sed -i "2iNIX_BIN_PREFIX=${nix}/bin/" direnvrc
substituteInPlace direnvrc \ substituteInPlace direnvrc \
--replace "grep" "${gnugrep}/bin/grep" \ --replace "grep" "${gnugrep}/bin/grep" \
--replace gzip "${gzip}/bin/gzip" \
--replace JQ= "JQ=${jq}/bin/jq" --replace JQ= "JQ=${jq}/bin/jq"
''; '';

View file

@ -206,11 +206,9 @@ nix_direnv_watch_file() {
JQ= JQ=
_jq() { _jq() {
if [[ -n $JQ ]] if [[ -n $JQ ]]; then
then
$JQ "$@" $JQ "$@"
elif has jq elif has jq; then
then
jq "$@" jq "$@"
else else
nix-shell --packages jq --run "$(join_args jq "$@")" nix-shell --packages jq --run "$(join_args jq "$@")"
@ -219,15 +217,10 @@ _jq() {
_nix_direnv_watches() { _nix_direnv_watches() {
local -n _watches=$1 local -n _watches=$1
# DIRENV_WATCHES is json | gzip (without header and trailer) | base64url # allow files under $XDG_DATA_HOME/direnv/allow are filtered out as not relevant
# allow files under $XDG_DATA_HOME/direenv/allow are filtered out as not relevant
# gzip header: https://datatracker.ietf.org/doc/html/rfc1952#page-6
mapfile -td "" _watches < <( mapfile -td "" _watches < <(
# shellcheck disable=2016 # shellcheck disable=2016
tr -- "-_" "+/" <<< "$DIRENV_WATCHES" \ direnv show_dump "${DIRENV_WATCHES}" \
| base64 --decode \
| (echo -ne "\x1f\x8b\x08\x00\x00\x00\x00\x00"; cat /dev/stdin) \
| (gzip --decompress 2>/dev/null || true) \
| _jq --join-output '.[] | select(.Exists ) | .Path | select(. | test($ENV.XDG_DATA_HOME + "/direnv/allow") | not) | (. + "\u0000")' | _jq --join-output '.[] | select(.Exists ) | .Path | select(. | test($ENV.XDG_DATA_HOME + "/direnv/allow") | not) | (. + "\u0000")'
) )
} }
@ -237,7 +230,6 @@ nix_direnv_manual_reload() {
_nix_direnv_manual_reload=1 _nix_direnv_manual_reload=1
} }
use_flake() { use_flake() {
_nix_direnv_preflight _nix_direnv_preflight