Skip to content

Conversation

ameertaweel
Copy link
Contributor

@ameertaweel ameertaweel commented May 4, 2025

Adds a command-not-found hook for Nushell.

Closes #264.

Copy link

@KiaraGrouwstra KiaraGrouwstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! looking good overall, mostly curious about the exit code.

for the record, looks like potential follow-ups would be:

  • make this easier to use
    1. new release
    2. update the package in nixpkgs, adding the script as in the flake here
    3. update the home-manager module to abstract out the include with an enableNushellIntegration option
  • add support for the NIX_AUTO_INSTALL / NIX_AUTO_RUN environment variables

1 => (do $single_pkg ($pkgs | get 0)),
_ => (do $multiple_pkgs $pkgs),
}
return $ret

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bash version uses exit code 127, maybe we should match that here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the return value from Nushell's command_not_found is not an exit code. It represents the message to display to the user. I literally started using Nushell a week ago, so please correct me if I'm wrong. But this is what I understood after reading this section from the Nushell book.

let single_pkg = { |pkg|
let lines = [
$"The program '($cmd_name)' is currently not installed."
""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this would be worth taking into consideration, but the (minor) formatting differences here could have some unintended effects on command-parsing tools (think thefuck, pay-respects)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I never used such tools so I didn't take that into consideration. Shall I install those tools locally and compare their behavior when using command-not-found.sh vs command-not-found.nu?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like so far upstream/PRs include at least:

.. so looks like so far these have been written general enough to not just trip over minor formatting differences (my fear), tho to be fair one may question where the burden lies of keeping their scripts working as well.

to be fair to them, maybe the one parsing for command not found might be easy enough to handle.
as for the old thefuck rule i made parsing for nix-env -iA , i guess i understand you opted to not complicate things here, while i realize flakes (and their nix cli v3 interface) have become fairly popular as well. in practice i think that situation is a bit complicated (most core contributors do not use flakes), tho tbf thefuck is a bit dead, so i'm kinda like whatever.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this hook for myself initially and wasn't planning to contribute it. That's why I focused on my specific usecase. Should I change command-not-found.nu to use the v3 interface only if flakes are enabled in nix.conf? That way it would make sense for both flake users and non-flake users.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, no biggie - it already looks great, the potential follow-ups i suggested i meant more as a note to self than a burden on you.

on flake checks to propose different commands, i think that's what command-not-found.sh was doing with its checks for manifest.json, so if you wanted to add something like that it could make sense to take some inspiration from their implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manifest.json check seems to tell us whether the user is using Nix profiles or not. And not whether they enabled flakes or not. However, I never used profiles / manifest.json so I'm kinda lost here. So we have four cases now:

  1. Flakes disabled / profiles disabled
  2. Flakes enabled / profiles disabled
  3. Flakes disabled / profiles enabled
  4. Flakes enabled / profiles enabled

Copy link

@KiaraGrouwstra KiaraGrouwstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like my earlier comments w.r.t. status code and NIX_AUTO_INSTALL / NIX_AUTO_RUN seem not applicable in the Nushell context, as @ameertaweel noted.

@bennofs @figsoda @RaitoBezarius would you mind reviewing as well? 🙏 ✌️

@RaitoBezarius RaitoBezarius merged commit 4b80066 into nix-community:master May 31, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for nushell
3 participants