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

Fix grep path when a grep alias exists #2122

Merged
merged 1 commit into from
Mar 14, 2022

Conversation

BarbUk
Copy link
Contributor

@BarbUk BarbUk commented Mar 11, 2022

Description

Fix function that try to find a full path for grep.

Motivation and Context

When a grep alias exists, _bash-it-grep and _bash-it-egrep are using /usr/bin/grep by default.
This break bash-it on debian based distribution, where grep is /bin/grep.

$ type -t grep
alias

$ type grep
grep is aliased to `grep --color=auto'

$ type -p egrep || type -p grep
# Output nothing

The fix is to use type -P:

-P	force a PATH search for each NAME, even if it is an alias,
    		builtin, or function, and returns the name of the disk file
    		that would be executed
-p	returns either the name of the disk file that would be executed,
    		or nothing if `type -t NAME' would not return `file'

How Has This Been Tested?

When using bash-it on a debian system, I have this error before each prompt command

-bash: /usr/bin/grep: No such file or directory

After the change, no more error.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

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

Lgtm

@NoahGorny NoahGorny merged commit 7cc2ced into Bash-it:master Mar 14, 2022
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.

2 participants