Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if command-not-found because it's not executable #8804

Closed
EdmundsEcho opened this issue Mar 16, 2022 · 7 comments
Closed

Warn if command-not-found because it's not executable #8804

EdmundsEcho opened this issue Mar 16, 2022 · 7 comments

Comments

@EdmundsEcho
Copy link

I have several directories in my PATH. I can see the path required to access the binary of interest. For some reason, I cannot get fish to find the binary.

The PATH

The path of interest is /opt/homebrew/bin

echo $PATH
/Users/edmund/.asdf/shims /Users/edmund/.asdf/bin /Users/edmund/.local/share/nvm/v16.14.1/bin /Users/edmund/.deno/bin /Users/edmund/.yarn/bin /Users/edmund/.local/bin /opt/homebrew/opt/llvm/bin /Users/edmund/.pyenv/shims /Users/edmund/.pyenv/bin /opt/homebrew/sbin **/opt/homebrew/bin** /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Users/edmund/.krew/bin /Users/edmund/.ghcup/bin /Users/edmund/.cargo/bin /opt/homebrew/opt/findutils/libexec/gnubin /opt/homebrew/opt/make/libexec/gnubin /opt/homebrew/opt/gawk/libexec/gnubin /opt/homebrew/opt/gsed/libexec/gnubin /opt/homebrew/opt/gnu-sed/libexec/gnubin /opt/homebrew/opt/grep/libexec/gnubin /opt/homebrew/opt/ed/libexec/gnubin /opt/homebrew/opt/gnu-tar/libexec/gnubin /opt/homebrew/opt/coreutils/libexec/gnubin /opt/homebrew/opt/libtool/libexec/gnubin

The content of that path

Note the presence of yarn

> ls /opt/homebrew/bin | ggrep yarn
yarn
yarnpkg

Fish not finding the binary

> yarn
fish: Unknown command: yarn

> which yarn
<empty line>

Other binaries can be found...

Fish can find other binaries in the same path (e.g., jq is in the directory)

> ls /opt/homebrew/bin | ggrep jq
jq

> which jq
/opt/homebrew/bin/jq

The question

What might prevent fish from finding the binary? (in this case yarn). How might I go about problem solving this?

Thank you in advance.

- E

@EdmundsEcho EdmundsEcho changed the title What might prevent fish from finding an exe in path? What might prevent fish from finding an exe in the PATH? Mar 16, 2022
@zanchey
Copy link
Member

zanchey commented Mar 17, 2022

You could see what the permissions on the file are:

stat /opt/homebrew/bin/yarn

The output of contains /opt/homebrew/bin $PATH will confirm that the path is set right.

@ridiculousfish
Copy link
Member

ridiculousfish commented Mar 17, 2022

Just to be sure, your $PATH does not actually contain:

**/opt/homebrew/bin**

including the asterisks? fish does not expand globs in $PATH.

@EdmundsEcho
Copy link
Author

EdmundsEcho commented Mar 17, 2022

@ridiculousfish -- correct :))

... per the suggestion use of contains (thank you @zanchey)

> if contains /opt/homebrew/bin $PATH; echo 'present'; else; echo 'missing'; end;
present

@faho
Copy link
Member

faho commented Mar 17, 2022

@EdmundsEcho In that case it appears /opt/homebrew/bin/yarn isn't executable by you. Which is why zanchey asked for you to run stat - that would include the permissions (but I'm not sure it's a thing on macOS).

I'm assuming test -x /opt/homebrew/bin/yarn; echo $status prints 1.

@EdmundsEcho
Copy link
Author

@zanchey The permissions was the issue. I confirmed this by toggling the -/+x to in fact show how fish will not find the binary if the permission does not include x.

chmod +x /opt/homebrew/bin/yarn

❯ which yarn
/opt/homebrew/bin/yarn

❯ chmod -x /opt/homebrew/bin/yarn
<empty line>

This behavior is a "norm" given that I can replicate it in bash.

This said, should it be a norm?

Receiving an error is in-line with what I would have intuited.

  • Is there a way for the shell to report something like a "execute permission denied"?

  • Would reporting such an error be a breaking-change for scripts that don't expect a return value in the event the permissions are missing?

  • Otherwise, might the difference between the empty response and the error be a useful hook allowing the programmer to "intervene" accordingly?

@EdmundsEcho
Copy link
Author

I'm assuming test -x /opt/homebrew/bin/yarn; echo $status prints 1.

@faho You got it. This is helpful. Thank you.

@faho faho closed this as completed in 71cfd25 Mar 17, 2022
@faho
Copy link
Member

faho commented Mar 17, 2022

Okay, here's what we can do:

If you try to execute a command, and none is found, we go through $PATH and try to find a file. If it's not executable, we print that with the command-not-found error.

In this specific case, it would have printed:

fish: Unknown command: yarn
fish: /opt/homebrew/bin/yarn exists but isn't executable

@faho faho added this to the fish 3.5.0 milestone Mar 17, 2022
@faho faho changed the title What might prevent fish from finding an exe in the PATH? Warn if command-not-found because it's not executable Mar 17, 2022
faho added a commit that referenced this issue Mar 31, 2022
This was already apparently supposed to work, but didn't because we
just overrode errno again.

This now means that, if a correctly named candidate exists, we don't
start the command-not-found handler.

See #8804
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants