refactor: rewrite command-not-found.sh in rust
closes #222 closes #126 should also fix #210 once this is finished
the implementation is adapted from locate and command-not-found.sh
draft because there are a few things I need to do:
- [x] actually replace the command-not-found.sh, including fish support
- [ ] complete
has_flakesto read user config, also consider keeping the previousmanifest.jsoncheck - [ ] better error handling, currently some errors are silently ignored
- [ ] make the code a bit more compact, the
Command::news feel a bit verbose
Wonderful!
The fish mechanism is simple but there are some nuances to consider that break the existing script (translated with babelfish); see https://github.com/fish-shell/fish-shell/issues/9806, https://github.com/fish-shell/fish-shell/issues/7902, https://github.com/fish-shell/fish-shell/pull/9517. (tl;dr it's run inside a substitution so you can't check tty through stdout, which might also interfere with the auto-run feature in terms of what stdout they get and how the exit status is handled. I wonder if anyone actually uses auto-run though? comma seems like a less error-prone way of getting essentially the same result...)
I just found a typo in the auto run error messages that's existed for a few years now
https://github.com/nix-community/nix-index/blob/73d96c85bc1bfe7c0cbd6269ea42119f65073cf9/command-not-found.sh#L56 https://github.com/nix-community/nix-index/blob/73d96c85bc1bfe7c0cbd6269ea42119f65073cf9/command-not-found.sh#L69
that's probably a sign that people are not really using this feature
Yeah, I would be happy to see it go. I think the main adaptation you'll need to make for fish is conditioning the pipe check on stdin or stderr, which unfortunately won't be as reliable (e.g. bad-command | ...). Not sure if there's a better check that could be done on the fish side and passed in via environment or something. Maybe it's fine to just check stderr and output there though? Seems okay for a piped command to print to stderr and then fail.
tbh I think it makes sense for this to run even if it is being piped into another command, maybe we can just remove the check altogether? @bennofs what do you think?
Yeah I dunno exactly what the rationale is if no output is going to stdout anyway. I think checking stderr would be good because you're printing output there that could be misinterpreted if you're piping it into another command with 2>&1 or similar.
(fwiw I think NIX_AUTO_INSTALL is even worse than NIX_AUTO_RUN – permanent imperative changes to system configuration in response to what could be a mere typo...)
I agree that NIX_AUTO_RUN / NIX_AUTO_INSTALL are probably fringe usecases that we can drop from upstream (people who want this behavior can use comma / use their own command-not-found handler).
We should include a message if NIX_AUTO_RUN / NIX_AUTO_INSTALL is set that explains the alternatives (comma, custom command not found) so users are not surprised that the feature is suddenly no longer available.
Just leaving a note here that I'm building and running nix-index with these changes on my systems and it behaves fine for me.
EDIT: Using bash on NixOS 24.05.