Fix direnv not using transformed values #960
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using
direnv
like the docs indicated I noticed that I no longer had completions for binaries in thePATH
. Turns out,direnv
outputs the variables to load as a string (which is normal) and they're being loaded as-is, without undergoing the transformation specified in$env.ENV_CONVERSIONS
.The code I changed gets the subset of variables that need to undergo transformation, applies the transformation and merges them with the original values.
I'm not 100% happy with the implementation as it's not that idiomatic, but I couldn't find an easy way to conditionally update a record and returning a new record in the process. I tried the following approaches:
While at it, I also took the chance to change indentation to 4 spaces (the other files I checked used it) and simplify the default value instead of accessing the length of the record.
I'm open to any changes to this, curious to see what other way there might be to achieve this in an easy and readable way! 😁