diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-11 14:52:11 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-11 14:52:11 +1300 |
commit | 6e8c6c521ae5d60427634be01b82fe61a79f192b (patch) | |
tree | 5349fc3e9838c69dbb6fd69f0234ea921ea446ea /sh/shrc.d/ls.sh | |
parent | Factor out zsh ENV hack into one file (diff) | |
download | dotfiles-6e8c6c521ae5d60427634be01b82fe61a79f192b.tar.gz dotfiles-6e8c6c521ae5d60427634be01b82fe61a79f192b.zip |
Refactor some conditionals
Diffstat (limited to 'sh/shrc.d/ls.sh')
-rw-r--r-- | sh/shrc.d/ls.sh | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/sh/shrc.d/ls.sh b/sh/shrc.d/ls.sh index 7e843cc7..1083dfca 100644 --- a/sh/shrc.d/ls.sh +++ b/sh/shrc.d/ls.sh @@ -12,26 +12,30 @@ unset -v LS_OPTIONS LS_COLORS # Define function proper ls() { - # -F to show trailing indicators of the filetype - # -q to replace control chars with '?' + # POSIX options: + ## -F to show trailing indicators of the filetype + ## -q to replace control chars with '?' set -- -Fq "$@" - - # If output is to a terminal, add -x to format entries across, not down - [ -t 1 ] && set -- -x "$@" - - # Add --block-size=K to always show the filesize in kibibytes - [ -e "$HOME"/.cache/sh/opt/ls/block-size ] && + ## -x to format entries across, not down, if output looks like a terminal + if [ -t 1 ] ; then + set -- -x "$@" + fi + + # GNU options: + ## Add --block-size=K to always show the filesize in kibibytes + if [ -e "$HOME"/.cache/sh/opt/ls/block-size ] ; then set -- --block-size=1024 "$@" - - # Add --color if the terminal has at least 8 colors - [ -e "$HOME"/.cache/sh/opt/ls/color ] && - [ "$({ tput colors||tput Co||echo 0; } 2>/dev/null)" -ge 8 ] && + fi + ## Add --color if the terminal has at least 8 colors + if [ -e "$HOME"/.cache/sh/opt/ls/color ] && + [ "$(exec 2>/dev/null;tput colors||tput Co||echo 0)" -ge 8 ] ; then set -- --color=auto "$@" - - # Add --time-style='+%Y-%m-%d %H:%M:%S' to show the date in my preferred - # (fixed) format - [ -e "$HOME"/.cache/sh/opt/ls/time-style ] && + fi + ## Add --time-style='+%Y-%m-%d %H:%M:%S' to show the date in my preferred + ## (fixed) format + if [ -e "$HOME"/.cache/sh/opt/ls/time-style ] ; then set -- --time-style='+%Y-%m-%d %H:%M:%S' "$@" + fi # If the operating system is FreeBSD, there are some specific options we # can add that might mean different things to e.g. GNU ls(1) |