aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/ls.bash
blob: d1afd04c24cbf9e6b6ea8ea8d57fcc100a38cd02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Function returns calculated options for ls
__lsopts() {
    local lsopts=
    local lshelp="$(ls --help 2>/dev/null)"
    if [[ "$lshelp" == *--color* ]]; then
        lsopts="${lsopts} --color=auto"
    fi
    printf '%s' "$lsopts"
}

# Alias ls with these options
alias ls="ls $(__lsopts)"

# Unset helper function
unset __lsopts

# Define and store appropriate colors for ls
if command -v dircolors &>/dev/null; then
    eval "$(dircolors --sh)"
fi