Skip to content

Commit f11e015

Browse files
authored
feat: add nushell support (#35)
1 parent ea21a6b commit f11e015

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ if command -v nix-your-shell > /dev/null; then
5555
fi
5656
```
5757

58+
### Nushell
59+
60+
> [!IMPORTANT]
61+
> Nushell version >=0.83.0 is required
62+
63+
> [!NOTE]
64+
> Nushell requires sourced configuration files to exist before `nu` is started.
65+
66+
Add to your `~/.config/nushell/config.nu`:
67+
68+
```nu
69+
source nix-your-shell.nu
70+
```
71+
72+
To generate `nix-your-shell.nu` file:
73+
74+
Either manually generate it:
75+
76+
```sh
77+
nix-your-shell nu | save nix-your-shell.nu
78+
```
79+
80+
Or populate its content through flakes and home-manager:
81+
82+
```nix
83+
{ config, pkgs, ... }: {
84+
home.file."${config.xdg.configHome}/nushell/nix-your-shell.nu".source = pkgs.nix-your-shell.generate-config "nu";
85+
}
86+
```
87+
5888
## Installation
5989

6090
You can either install `nix-your-shell` from this repository or from `nixpkgs`.

data/env.nu

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# If you see this output, you probably forgot to pipe it into `source`:
2+
# nix-your-shell nu | save nix-your-shell.nu
3+
4+
def call-wrapper (command: string, args: list<string>) {
5+
if not (which nix-your-shell | is-empty) {
6+
let args = ["--"] ++ $args
7+
8+
run-external nix-your-shell $command $args
9+
} else {
10+
run-external $command $args
11+
}
12+
}
13+
14+
extern-wrapped nix-shell (...args) {
15+
call-wrapper nix-shell $args
16+
}
17+
18+
extern-wrapped nix (...args) {
19+
call-wrapper nix $args
20+
}

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
cargo fmt --check && echo "\`cargo fmt\` is OK"
7171
cargo clippy -- --deny warnings && echo "\`cargo clippy\` is OK"
7272
'';
73+
74+
passthru.generate-config = shell: final.runCommand "nix-your-shell-config" { } ''
75+
${final.nix-your-shell}/bin/nix-your-shell ${shell} >> $out
76+
'';
7377
};
7478
}
7579
);

src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ fn main() -> eyre::Result<()> {
8787
include_str!("../data/env.fish")
8888
}
8989

90+
ShellKind::Nushell => {
91+
include_str!("../data/env.nu")
92+
}
93+
9094
ShellKind::Other(shell) => {
9195
return Err(eyre!(
9296
"I don't know how to generate a shell environment for `{shell}`"
9397
))
94-
.note("Supported shells are: `zsh`, `fish`, and `bash`")
98+
.note("Supported shells are: `zsh`, `fish`, `nushell` and `bash`")
9599
}
96100
}
97101
.to_owned();
@@ -110,8 +114,7 @@ fn main() -> eyre::Result<()> {
110114
let current_exe =
111115
current_exe().wrap_err("Unable to determine absolute path of `nix-your-shell`")?;
112116
if args.absolute || !executable_is_on_path(&current_exe)? {
113-
shell_code =
114-
shell_code.replace("nix-your-shell", &format!("{current_exe} --absolute"));
117+
shell_code = shell_code.replace("nix-your-shell", current_exe.as_str());
115118
}
116119

117120
println!("{shell_code}");

src/shell.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub enum ShellKind {
2020
/// <https://www.gnu.org/software/bash/>
2121
Bash,
2222

23+
/// The `nu` shell
24+
/// <https://www.nushell.sh/>
25+
Nushell,
26+
2327
/// A different shell.
2428
Other(String),
2529
}
@@ -30,6 +34,7 @@ impl Display for ShellKind {
3034
ShellKind::Zsh => write!(f, "zsh"),
3135
ShellKind::Fish => write!(f, "fish"),
3236
ShellKind::Bash => write!(f, "bash"),
37+
ShellKind::Nushell => write!(f, "nu"),
3338
ShellKind::Other(shell) => write!(f, "{shell}"),
3439
}
3540
}
@@ -57,6 +62,8 @@ impl Shell {
5762
ShellKind::Fish
5863
} else if file_name.starts_with("bash") {
5964
ShellKind::Bash
65+
} else if file_name.starts_with("nu") {
66+
ShellKind::Nushell
6067
} else {
6168
ShellKind::Other(file_name.to_string())
6269
};

0 commit comments

Comments
 (0)