aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/ls.sh
blob: 7e916239cf2e39df0d7f3526b73f9fb343024b60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Our ~/.profile should already have made a directory with the supported
# options for us; if not, we won't be wrapping ls(1) with a function at all
[ -d "$HOME"/.cache/ls ] || return

# Define function proper
ls() {

    # Add --block-size=K to always show the filesize in kibibytes
    [ -e "$HOME"/.cache/ls/block-size ] &&
        set -- --block-size=1024 "$@"

    # Add --classify to show trailing indicators of the filetype
    [ -e "$HOME"/.cache/ls/classify ] &&
        set -- --classify "$@"

    # Add --color if the terminal has at least 8 colors
    [ -e "$HOME"/.cache/ls/color ] &&
    [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
        set -- --color=auto "$@"

    # Add --format=horizontal to print entries in a saner way
    [ -e "$HOME"/.cache/ls/format ] &&
        set -- --format=horizontal "$@"

    # Add --hide-control-chars if present; we always want this interactively,
    # even if the output is to a pager; we shouldn't be trying to script ls(1)
    # output anyway
    [ -e "$HOME"/.cache/ls/hide-control-chars ] &&
        set -- --hide-control-chars "$@"

    # Add --time-style='+%Y-%m-%d %H:%M:%S' to show the date in my preferred
    # format
    [ -e "$HOME"/.cache/ls/time-style ] &&
        set -- --time-style='+%Y-%m-%d %H:%M:%S' "$@"

    # Run ls(1) with the concluded arguments
    command ls "$@"
}