diff --git a/README.md b/README.md index e268950..087701d 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,14 @@ some limited ability to make the manipulations dynamic. ![shadowenv in action](https://burkelibbey.s3.amazonaws.com/shadowenv.gif) -In order to use shadowenv, add a line to your shell profile (`.zshrc`, `.bash_profile`, or -`config.fish`) reading: +In order to use shadowenv, add a line to your shell profile (`.zshrc`, `.bash_profile`, +`config.fish`, or `config.nu`) reading: ```bash eval "$(shadowenv init bash)" # for bash eval "$(shadowenv init zsh)" # for zsh shadowenv init fish | source # for fish +# for nushell, paste the output of `shadowenv init nushell` into config.nu ``` With this code loaded, upon entering a directory containing a `.shadowenv.d` directory, diff --git a/sh/shadowenv.nushell.in b/sh/shadowenv.nushell.in new file mode 100644 index 0000000..8ed279b --- /dev/null +++ b/sh/shadowenv.nushell.in @@ -0,0 +1,20 @@ +$env.config = ($env.config | upsert hooks.env_change.PWD { |config| + let existing = $config | get -o hooks.env_change.PWD | default [] + $existing | append {|| + mut flags = ["--json"] + + if ($env.__shadowenv_force_run? | default false) { + hide-env -i __shadowenv_force_run + $flags = ($flags | append "--force") + } + + let result = @SELF@ hook ...$flags | complete + if $result.exit_code != 0 { + return + } + + $result.stdout | from json | get -o exported | default {} | load-env + } +}) + +$env.__shadowenv_force_run = true diff --git a/src/cli.rs b/src/cli.rs index 8c3d56c..e3af9f1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -103,6 +103,9 @@ pub enum InitCmd { /// Prints a script which can be eval'd by fish to set up shadowenv. Fish, + + /// Prints a script which can be eval'd by nushell to set up shadowenv. + Nushell, } /// Options shared by all init subcommands diff --git a/src/init.rs b/src/init.rs index b231597..00027f0 100644 --- a/src/init.rs +++ b/src/init.rs @@ -21,6 +21,11 @@ pub fn run(cmd: InitCmd) { include_bytes!("../sh/shadowenv.fish.in"), true, // Fish doesn't use hookbook ), + Nushell => print_script( + pb, + include_bytes!("../sh/shadowenv.nushell.in"), + true, // Nushell doesn't use hookbook + ), }; }