aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/grep.bash
blob: f2586562af56edb8f85cf9c577230c48c766301c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Function returns calculated options for grep
__grepopts() {
    local grepopts='-I'
    local grephelp="$(grep --help 2>/dev/null)"
    [[ "$grephelp" == *--color* ]] \
        && grepopts="${grepopts} --color=auto"
    [[ "$grephelp" == *--exclude* ]] \
        && grepopts="${grepopts} --exclude=.git{,ignore,modules}"
    [[ "$grephelp" == *--exclude-dir* ]] \
        && grepopts="${grepopts} --exclude-dir=.{cvs,git,hg,svn}"
    printf '%s' "$grepopts"
}

# Alias grep with those options
alias grep="grep $(__grepopts)"

# Unset helper function
unset __grepopts