
# 2022-06-12 - Alex - only configure less if we have a tty.
if [ -x /usr/bin/tty ] && /usr/bin/tty -s; then

    export LESS="-R"

    export GROFF_NO_SGR=1         # For Konsole and Gnome-terminal

    if [ -x "$(command -v lesspipe)" ]; then
        eval "$(lesspipe)"
    fi

    if [ -x /usr/bin/tput ]; then
        if LESS_TERMCAP_mb="$(tput bold; tput setaf 2)"; then
            # green
            export LESS_TERMCAP_mb
        fi

        if LESS_TERMCAP_md="$(tput bold; tput setaf 6)"; then
            # cyan
            export LESS_TERMCAP_md
        fi

        if LESS_TERMCAP_me="$(tput sgr0)"; then
            export LESS_TERMCAP_me
        fi

        if LESS_TERMCAP_so="$(tput bold; tput setaf 3; tput setab 4)"; then
            # yellow on blue
            export LESS_TERMCAP_so
        fi

        if LESS_TERMCAP_se="$(tput rmso; tput sgr0)"; then
            export LESS_TERMCAP_se
        fi

        if LESS_TERMCAP_us="$(tput smul; tput bold; tput setaf 7)"; then
            # white
            export LESS_TERMCAP_us
        fi

        if LESS_TERMCAP_ue="$(tput rmul; tput sgr0)"; then
            export LESS_TERMCAP_ue
        fi

        if LESS_TERMCAP_mr="$(tput rev)"; then
            export LESS_TERMCAP_mr
        fi

        if LESS_TERMCAP_mh="$(tput dim)"; then
            export LESS_TERMCAP_mh
        fi

        if LESS_TERMCAP_ZN="$(tput ssubm)"; then
            export LESS_TERMCAP_ZN
        fi

        if LESS_TERMCAP_ZV="$(tput rsubm)"; then
            export LESS_TERMCAP_ZV
        fi

        if LESS_TERMCAP_ZO="$(tput ssupm)"; then
            export LESS_TERMCAP_ZO
        fi

        if LESS_TERMCAP_ZW="$(tput rsupm)"; then
            export LESS_TERMCAP_ZW
        fi
    else
        echo "Couldn't find tput executable, not setting \$LESS_TERMCAP_* values."
    fi
fi
