aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/grep.bash
blob: be2017419f4a328601bc1cf8708f7a4b55e638a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Define function wrapper for grep(1) with --color option if GREP_COLORS is
# set; checks that color is available in the terminal within the function
if [[ ! -n $GREP_COLORS ]] ; then
    return
fi

# Define function proper
grep() {
    local -i colors
    colors=$( {
        tput Co || tput colors
    } 2>/dev/null )
    if ((colors >= 8)) ; then
        command grep --color=auto "$@"
    else
        command grep "$@"
    fi
}