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

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