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 /bash/bashrc.d/ls.bash | |
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.
Diffstat (limited to 'bash/bashrc.d/ls.bash')
-rw-r--r-- | bash/bashrc.d/ls.bash | 28 |
1 files changed, 15 insertions, 13 deletions
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[@]}" "$@" } |