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

[BUG] whereis -b not supported on macOS #19

Closed
1 of 2 tasks
HaleTom opened this issue Jan 12, 2022 · 4 comments
Closed
1 of 2 tasks

[BUG] whereis -b not supported on macOS #19

HaleTom opened this issue Jan 12, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@HaleTom
Copy link

HaleTom commented Jan 12, 2022

Issue observed in the following shell(s):

  • Bash
  • Zsh

Describe the bug
Upon shell startup:

whereis: illegal option -- b
usage: whereis program [...]
Can't use SmartCd: fzf not found !

I suggest you do:

is_cmd () {
        command -v "$1" >&/dev/null
}

and then:

	if is_cmd fdfind; then

Expected behaviour
No error

@CodesOfRishi
Copy link
Owner

I think this can fail if the expected executable name that I am passing to command -v is not an installed executable, but an alias!

@CodesOfRishi CodesOfRishi added the bug Something isn't working label Jan 12, 2022
@CodesOfRishi
Copy link
Owner

I'm not sure, but I think I should go with the hash command instead.

@CodesOfRishi CodesOfRishi changed the title [BUG] whence -b not supported on macOS [BUG] whereis -b not supported on macOS Jan 12, 2022
CodesOfRishi added a commit that referenced this issue Jan 13, 2022
Use `hash` command instead of `whereis -b` to check if an executable
exist or not as it's POSIX compatible.
@HaleTom
Copy link
Author

HaleTom commented Jan 14, 2022

You're right on the aliases!

To avoid the "determine and remember" overhead of re-hashing, when I want to get a binary's path, I use:

bin_path () {
        if [[ -n ${ZSH_VERSION:-} ]]; then
                builtin whence -cp "$1" 2> /dev/null
        else
                builtin type -P "$1"
        fi
}

Tweaking for silent, return value only:

has_bin () {
        if [[ -n ${ZSH_VERSION:-} ]]; then
                builtin whence -cp "$1" >& /dev/null
        else
                builtin type -P "$1"  >& /dev/null
        fi
}

@CodesOfRishi CodesOfRishi reopened this Jan 14, 2022
@CodesOfRishi
Copy link
Owner

The concern regarding re-hashing is moved to another issue #22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants