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

Update grep.sh #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bin/profile.d/alias.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ if ( echo $- | grep i >/dev/null 2>&1 ); then
fi

fi

my_grep_options=(--color=auto) # I like color, without deprecation warnings

if ( _version_gte "$( grep -V | head -n 1 | sed 's/[^0-9]*\([0-9]*\.[0-9]*\).*/\1/' )" "2.5.2" ); then
# The following adds new options for grep to exclude: CVS, .cvs, .git, .hg, .svn directories
my_grep_options=(
${my_grep_options[@]} --exclude-dir=CVS) # Excludes CVS directories for CVS
${my_grep_options[@]} --exclude-dir=.cvs) # Excludes .cvs directories for CVS
${my_grep_options[@]} --exclude-dir=.git) # Excludes .git directories for Git
${my_grep_options[@]} --exclude-dir=.hg) # Excludes .hg directories for Mercurial
${my_grep_options[@]} --exclude-dir=.svn) # Excludes .svn directors for Subversion
Copy link
Owner

Choose a reason for hiding this comment

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

Syntax error, too many closing parenthesis (one per line)

Additionally (if it weren't for the syntax error) this would result in --color=auto --exclude-dir=CVS --color=auto --exclude-dir=.cvs --color=auto --exclude-dir=.git --color=auto --exclude-dir=.hg --color=auto --exclude-dir=.svn -- You only need ${my_grep_options[@]} once up-front.

)
alias grep="grep $my_grep_options"
Copy link
Owner

Choose a reason for hiding this comment

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

I suggest using the same ${my_grep_options[@]} here

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure I follow since this conflicts with your initial feedback sir:

so it would be better to write alias grep="grep ..."

Copy link
Author

Choose a reason for hiding this comment

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

Oh I think I see what you mean. Instead of the $my_grep_options use ${my_grep_options[@]}...right?

unset my_grep_options
Copy link
Owner

Choose a reason for hiding this comment

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

These two lines should be outside the if-block so that --color=auto is applied even if --exclude-dir isn't supported.

fi
10 changes: 0 additions & 10 deletions bin/profile.d/grep.sh

This file was deleted.