diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-05-31 15:52:10 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-05-31 15:52:10 +1200 |
commit | 0a95c126e8853996d4025a9d2ad8aab735b5bc05 (patch) | |
tree | 0fde3a21a878a9e88c9cac9ca45f420dd29e9047 /bash/bashrc.d | |
parent | Consistent color count method (diff) | |
download | dotfiles-0a95c126e8853996d4025a9d2ad8aab735b5bc05.tar.gz dotfiles-0a95c126e8853996d4025a9d2ad8aab735b5bc05.zip |
Avoid condition definition of functions
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/grep.bash | 25 | ||||
-rw-r--r-- | bash/bashrc.d/ls.bash | 25 | ||||
-rw-r--r-- | bash/bashrc.d/vim.bash | 23 |
3 files changed, 41 insertions, 32 deletions
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 +} + diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash index 7093cd7c..c47859c9 100644 --- a/bash/bashrc.d/ls.bash +++ b/bash/bashrc.d/ls.bash @@ -1,15 +1,18 @@ # Define function wrapper for ls(1) with --color option if LS_COLORS is set; # checks that color is available in the terminal within the function -if [[ $LS_COLORS ]] ; then - ls() { - local -i colors=$( { - tput Co || tput colors - } 2>/dev/null ) - if ((colors >= 8)) ; then - command ls --color=auto "$@" - else - command ls "$@" - fi - } +if ! [[ $LS_COLORS ]] ; then + return fi +# Define function proper +ls() { + local -i colors=$( { + tput Co || tput colors + } 2>/dev/null ) + if ((colors >= 8)) ; then + command ls --color=auto "$@" + else + command ls "$@" + fi +} + diff --git a/bash/bashrc.d/vim.bash b/bash/bashrc.d/vim.bash index 9b598192..4584ae1d 100644 --- a/bash/bashrc.d/vim.bash +++ b/bash/bashrc.d/vim.bash @@ -1,13 +1,16 @@ # If Vim exists on the system, use it instead of ex, vi, and view -if hash vim 2>/dev/null ; then - ex() { - command vim -e "$@" - } - vi() { - command vim "$@" - } - view() { - command vim -R "$@" - } +if ! hash vim 2>/dev/null ; then + return fi +# Define functions proper +ex() { + command vim -e "$@" +} +vi() { + command vim "$@" +} +view() { + command vim -R "$@" +} + |