Skip to content

Commit 4b80066

Browse files
Merge pull request #271 from AmeerTaweel/master
feat(command-not-found): Support Nushell
2 parents 03b8617 + 4157319 commit 4b80066

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ Or run it once with:
8383

8484
A [`home-manager` module](https://nix-community.github.io/home-manager/options.html#opt-programs.nix-index.enable) is now available to integrate `nix-index` with `bash`, `zsh`, and `fish` using this script.
8585

86+
You can also use `command-not-found.nu` as a Nushell hook by adding the
87+
following to your Nushell config:
88+
89+
```nix
90+
programs.nushell = {
91+
enable = true;
92+
extraConfig = ''
93+
$env.config.hooks.command_not_found = source ${pkgs.nix-index}/etc/profile.d/command-not-found.nu
94+
'';
95+
};
96+
```
97+
8698
## Contributing
8799
If you find any missing features that you would like to implement, I'm very happy about any PRs! You can also create an issue first if the feature is more complex so we can discuss possible implementations.
88100

command-not-found.nu

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{ |cmd_name|
2+
let install = { |pkgs|
3+
$pkgs | each {|pkg| $" nix shell nixpkgs#($pkg)" }
4+
}
5+
let run_once = { |pkgs|
6+
$pkgs | each {|pkg| $" nix shell nixpkgs#($pkg) --command '($cmd_name) ...'" }
7+
}
8+
let single_pkg = { |pkg|
9+
let lines = [
10+
$"The program '($cmd_name)' is currently not installed."
11+
""
12+
"You can install it by typing:"
13+
(do $install [$pkg] | get 0)
14+
""
15+
"Or run it once with:"
16+
(do $run_once [$pkg] | get 0)
17+
]
18+
$lines | str join "\n"
19+
}
20+
let multiple_pkgs = { |pkgs|
21+
let lines = [
22+
$"The program '($cmd_name)' is currently not installed. It is provided by several packages."
23+
""
24+
"You can install it by typing one of the following:"
25+
(do $install $pkgs | str join "\n")
26+
""
27+
"Or run it once with:"
28+
(do $run_once $pkgs | str join "\n")
29+
]
30+
$lines | str join "\n"
31+
}
32+
let pkgs = (@out@/bin/nix-locate --minimal --no-group --type x --type s --top-level --whole-name --at-root $"/bin/($cmd_name)" | lines)
33+
let len = ($pkgs | length)
34+
let ret = match $len {
35+
0 => null,
36+
1 => (do $single_pkg ($pkgs | get 0)),
37+
_ => (do $multiple_pkgs $pkgs),
38+
}
39+
return $ret
40+
}

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"(examples|src)(/.*)?"
2727
''Cargo\.(toml|lock)''
2828
''command-not-found\.sh''
29+
''command-not-found\.nu''
2930
];
3031

3132
cargoLock = {
@@ -40,6 +41,9 @@
4041
substituteInPlace command-not-found.sh \
4142
--subst-var out
4243
install -Dm555 command-not-found.sh -t $out/etc/profile.d
44+
substituteInPlace command-not-found.nu \
45+
--subst-var out
46+
install -Dm555 command-not-found.nu -t $out/etc/profile.d
4347
'';
4448

4549
meta = with lib; {

0 commit comments

Comments
 (0)