diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-24 18:10:44 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-24 18:10:44 +1200 |
commit | d184357767cfa266a6d8a32016f66e8e6bd1f17f (patch) | |
tree | 973f67cd0b5dbead3bcd9020820b6b5952577a7a | |
parent | Use Bashy syntax to build GREP_OPTIONS more nicely (diff) | |
download | dotfiles-d184357767cfa266a6d8a32016f66e8e6bd1f17f.tar.gz dotfiles-d184357767cfa266a6d8a32016f66e8e6bd1f17f.zip |
Undo hare-brained last few commits
GREP_OPTIONS doesn't work if it's not exported, which ought to have been
painfully obvious. Oh well.
-rw-r--r-- | bash/bashrc.d/grep.bash | 43 | ||||
-rw-r--r-- | bash/bashrc.d/ls.bash | 28 | ||||
-rw-r--r-- | sh/profile.d/grep.sh | 2 |
3 files changed, 35 insertions, 38 deletions
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash index 3605a925..3f8e44e0 100644 --- a/bash/bashrc.d/grep.bash +++ b/bash/bashrc.d/grep.bash @@ -1,39 +1,34 @@ +# Store whether we have colors in a variable +declare -i colors +colors=$( { + tput Co || tput colors +} 2>/dev/null ) + # Store grep(1)'s --help output in a variable grep_help=$(grep --help 2>/dev/null) -# Use GREP_OPTIONS to add some useful options to grep(1) calls if applicable -declare -a grep_options +# Use GREPOPTS to add some useful options to grep(1) calls if applicable; we +# use a function wrapper to do this, rather than GREP_OPTIONS as we don't want +# to change grep(1)'s actual behaviour inside scripts +declare -a GREPOPTS +if [[ -n $GREP_COLORS ]] && ((colors >= 8)) ; then + GREPOPTS=("${GREPOPTS[@]}" --color=auto) +fi if [[ $grep_help == *--binary-files* ]] ; then - grep_options=("${grep_options[@]}" --binary-files=without-match) + GREPOPTS=("${GREPOPTS[@]}" --binary-files=without-match) fi if [[ $grep_help == *--exclude* ]] ; then - grep_options=("${grep_options[@]}" --exclude={.gitignore,.gitmodules}) + GREPOPTS=("${GREPOPTS[@]}" --exclude={.gitignore,.gitmodules}) fi if [[ $grep_help == *--exclude-dir* ]] ; then - grep_options=("${grep_options[@]}" --exclude-dir={.cvs,.git,.hg,.svn}) + GREPOPTS=("${GREPOPTS[@]}" --exclude-dir={.cvs,.git,.hg,.svn}) fi -GREP_OPTIONS=${grep_options[*]} -unset -v grep_options -# We're done parsing grep(1)'s --help output now -unset -v grep_help - -# 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 +# Done, unset helper vars +unset -v grep_help colors # 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 + command grep "${GREPOPTS[@]}" "$@" } diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash index 31beb302..0fd246fe 100644 --- a/bash/bashrc.d/ls.bash +++ b/bash/bashrc.d/ls.bash @@ -1,19 +1,21 @@ -# 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 [[ ! -n $LS_COLORS ]] ; then - return +# Store whether we have colors in a variable +declare -i colors +colors=$( { + tput Co || tput colors +} 2>/dev/null ) + +# Use LSOPTS to add some useful options to ls(1) calls if applicable; we use a +# function wrapper to do this +declare -a LSOPTS +if [[ -n $LS_COLORS ]] && ((colors >= 8)) ; then + LSOPTS=("${LSOPTS[@]}" --color=auto) fi +# Done, unset helper var +unset -v colors + # Define function proper ls() { - local -i colors - colors=$( { - tput Co || tput colors - } 2>/dev/null ) - if ((colors >= 8)) ; then - command ls --color=auto "$@" - else - command ls "$@" - fi + command ls "${LSOPTS[@]}" "$@" } diff --git a/sh/profile.d/grep.sh b/sh/profile.d/grep.sh index bcdb009e..4e27b087 100644 --- a/sh/profile.d/grep.sh +++ b/sh/profile.d/grep.sh @@ -1,7 +1,7 @@ # Store grep(1)'s --help output in a variable grep_help=$(grep --help 2>/dev/null) -# Use GREP_COLORS to add color output to grep(1) if option available +# Run dircolors(1) to export LS_COLORS if available and appropriate case $grep_help in *--color*) GREP_COLORS='ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36' |