Skip to content

Conversation

gromgit
Copy link
Contributor

@gromgit gromgit commented Sep 21, 2025

Addresses #20740.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Copy link
Member

@ZhongRuoyu ZhongRuoyu left a comment

Choose a reason for hiding this comment

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

Will this break existing usage? Or can this be done in a way that it doesn't?

https://github.com/search?q=%22brew%20command-not-found-init%22%20lang%3Afish&type=code

I understand that this is fixing an inconsistency, but it seems like this special logic for Fish (as compared to Bash and Zsh) has lived since Fish support was added (Homebrew/homebrew-command-not-found@ebfe42a). I'm not a Fish user so I can't tell why it was done that way though.

@ZhongRuoyu
Copy link
Member

ZhongRuoyu commented Sep 21, 2025

How about this: given that source (brew command-not-found-init) in Fish will print out the following after this change:

$ source (brew command-not-found-init)
source: Error encountered while sourcing file ''# License: MIT'':
source: No such file or directory

We update the first line of handler.fish as follows:

--- a/Library/Homebrew/command-not-found/handler.fish
+++ b/Library/Homebrew/command-not-found/handler.fish
@@ -1,3 +1,4 @@
+# If see this error, please update your config.fish following https://docs.brew.sh/Command-Not-Found
 # License: MIT
 # The license text can be found in Library/Homebrew/command-not-found/LICENSE
 

... and update the documentation accordingly (or not, because the documented way still works), so that people relying on the existing behaviour can migrate without confusion:

$ source (brew command-not-found-init)
source: Error encountered while sourcing file ''# If see this error, please update your config.fish following https://docs.brew.sh/Command-Not-Found'':
source: No such file or directory

Anyone using the old `. (brew command-not-found-init)` formulation will see this:
```
> . (brew command-not-found-init)
.: Error encountered while sourcing file ''# See https://docs.brew.sh/Command-Not-Found for current setup instructions'':
.: No such file or directory
```
@gromgit
Copy link
Contributor Author

gromgit commented Sep 21, 2025

Thanks for the suggestion, @ZhongRuoyu! Users of the old formulation will now see this instead:

> . (brew command-not-found-init)
.: Error encountered while sourcing file ''# See https://docs.brew.sh/Command-Not-Found for current setup instructions'':
.: No such file or directory

@ZhongRuoyu
Copy link
Member

Thanks @gromgit!

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Sep 21, 2025
Merged via the queue into Homebrew:main with commit 23d4a36 Sep 21, 2025
38 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.

3 participants