logoalt Hacker News

0xbadcafebee12/08/20242 repliesview on HN

I don't really understand why people use direnv, but you could easily replace it with a shell script that could load anything you want when entering a directory.

You basically just write a script that hooks into your shell (using your shell's existing hooks, like PROMPT_COMMAND for bash) and have it load a shell script in any directory you enter.

Obviously this is a security risk, as you could enter a directory controlled by a hacker. This is why (presumably) they only deal with exported variables, though even that's dangerous.


Replies

Nullabillity12/08/2024

direnv unloads the directory's environment as soon as I leave it, so I don't have to worry about the provenance of any one given shell instance. All I have to care about is its current working dir.

PufPufPuf12/08/2024

...or you could use a tool somebody already wrote, which even includes a security mechanism.