diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-05-30 23:56:54 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-05-30 23:56:54 +1200 |
commit | d20cb23998c672fea3ef344d836102a781517c80 (patch) | |
tree | bbec18590b578f7eee131203bf689e0704602df9 /bash/bashrc.d/ls.bash | |
parent | Remove a few notes about ~/.profile (diff) | |
download | dotfiles-d20cb23998c672fea3ef344d836102a781517c80.tar.gz dotfiles-d20cb23998c672fea3ef344d836102a781517c80.zip |
Overhaul grep(1) and ls(1) options and wrappers
Diffstat (limited to 'bash/bashrc.d/ls.bash')
-rw-r--r-- | bash/bashrc.d/ls.bash | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash index a559a44a..322644c5 100644 --- a/bash/bashrc.d/ls.bash +++ b/bash/bashrc.d/ls.bash @@ -1,26 +1,13 @@ -# Return appropriate options for ls -lsopts() { - - # Snarf the output of `ls --help` into a variable - local lshelp=$(ls --help 2>/dev/null) - - # Start collecting available options - local -a lsopts - - # If the --color option is available and we have a terminal that supports - # at least eight colors, add --color=auto to the options - local colors=$(tput colors 2>/dev/null) - if [[ $lshelp == *--color* ]] && ((colors >= 8)) ; then - lsopts=("${lsopts[@]}" --color=auto) - fi - - # Print the options as a single string, space-delimited - printf %s "${lsopts[*]}" -} - -# Alias ls with these options -alias ls="ls $(lsopts)" - -# Unset helper function -unset -f lsopts +# 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 colors=$(tput colors 2>/dev/null) + if ((colors >= 8)) ; then + command ls --color=auto "$@" + else + command ls "$@" + fi + } +fi |