nushell/post.org
2020-06-05 05:37:11 +02:00

1.8 KiB
Raw Blame History

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) ``` #inside a .nu-file in a whitelisted directory [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"] ```

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:

  • ´add_env´ does not overwrite variables. Need ´add_env_force´?
  • `ctx.get_env()` in `cli.rs` lacks access to the config, which is required. Is it ok to do it through the sync call instead?

TODO: take care of situation where a directory overwrites an existing .nu conf.

—-

#