diff options
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[@]}" "$@" } |