From 0a95c126e8853996d4025a9d2ad8aab735b5bc05 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 31 May 2015 15:52:10 +1200 Subject: Avoid condition definition of functions --- bash/bashrc.d/grep.bash | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'bash/bashrc.d/grep.bash') diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash index 0eedb451..12354d78 100644 --- a/bash/bashrc.d/grep.bash +++ b/bash/bashrc.d/grep.bash @@ -1,15 +1,18 @@ # 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 [[ $GREP_COLORS ]] ; then - grep() { - local -i colors=$( { - tput Co || tput colors - } 2>/dev/null ) - if ((colors >= 8)) ; then - command grep --color=auto "$@" - else - command grep "$@" - fi - } +if ! [[ $GREP_COLORS ]] ; then + return fi +# Define function proper +grep() { + local -i colors=$( { + tput Co || tput colors + } 2>/dev/null ) + if ((colors >= 8)) ; then + command grep --color=auto "$@" + else + command grep "$@" + fi +} + -- cgit v1.2.3