# 2021-02-28 - Alex - if $LS_COLORS hasn't been set yet, try to set it.
if [ "${LS_COLORS:-false}" = 'false' ] && [ -x "$(command -v dircolors)" ]; then
    if [ -n "$BASH_VERSION" ]; then
        eval "$(dircolors -b)"
    else
        # be more conservative for non-bash shells (POSIX?)
        eval "$(dircolors)"
    fi
fi

# 2021-02-13 - Alex - only use colored output if $LS_COLORS was set, likely by `dircolors -b`
if [ "${LS_COLORS:-false}" != 'false' ]; then
    alias ls='ls --color=auto'
    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
    if [ -n "$BASH_VERSION" ] && [ -n "$COLUMNS" ]; then
        alias diff='diff --color=auto --width=$COLUMNS'
    else
        alias diff='diff --color=auto'
    fi

    export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
    # 2021-02-28 - Alex - colorize `zpool status` output if $ZFS_COLOR is defined
    export ZFS_COLOR='yes'
else
    # aliases for non-colored terminals
    if [ -n "$BASH_VERSION" ] && [ -n "$COLUMNS" ]; then
        alias diff='diff --width=$COLUMNS'
    fi
fi

