nushell/post.org

35 lines
1.8 KiB
Org Mode
Raw Normal View History

2020-06-05 05:37:11 +02:00
# WIP: Per directory env-variables
For #86
Environment variables are added if you have created a file called .nu inside a whitelisted directory, formatted as shown below. (I am, of course, open to change everything about this)
```
[env]
var = "value"
anothervar = "anothervalue"
```
In order for a .nu-file to be read, the directory it is in must be listed in the `nu_env_dirs` variable in nushell's `config.toml`.
```
nu_env_dirs = ["/home/sam", "/home/sam/github", "/home/sam/github/test"]
```
2020-06-06 11:45:58 +02:00
This was implemented for the sake of security. I do not believe that it is appropiate for nushell to pick up random .nu-files unless
the user has explicitly said that it's alright. An adversary could hide a .nu-file in an otherwise unsuspicous folder that you download,
2020-06-06 03:31:30 +02:00
and now you suddenly have nushell picking up whatever environment variables they set.
This meant that the code necessarily become more involved than just looking for a .nu-file in the current directory and applying its variables,
but this extra code also allowed for some other nice features and behavior which is listed below.
2020-06-05 05:37:11 +02:00
Behavior:
- If you are in a subdirectory to a directory with a .nu-file, the vars in that .nu-file are applied.
- If you leave a directory which set some variables, the variables are unset.
- If a directory contains a .nu with an environment variable already set, the old value will be overwritten with the value from the .nu. This holds even if the old value was set by a .nu in a parent directory.
- The overwritten value is restored when you leave the directory.
- TODO: What happens if you overwrite twice?
Questions:
2020-06-06 03:31:30 +02:00
`remove_env()` accesses the environment directly to remove variables.
Just using what I think was expected, envs.entries.remove(key), does not work.
If this is a problem, how can I make it work better with existing code?
2020-06-05 05:37:11 +02:00
----
#