# Copyright (c) 2017 Mario Castelán Castro
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

function set_color () {
    local RED GREEN CYAN END_COLOR
    RED="$(tput setaf 1)" &&
    GREEN="$(tput setaf 2)" &&
    CYAN="$(tput setaf 6)" &&
    END_COLOR="$(tput sgr0)"

    if [ $? != 0 ]; then
        local PRINT_EXIT_STATUS=\
"\$(E=\$?
if [ \$E == 0 ]; then
    echo \"[\$E]\"
else
    echo \"*\$E*\"
fi )"
        PS1="\u@\h $PRINT_EXIT_STATUS [\$PWD]\n\\$ "
    else
        if [ $(id -u) == 0 ]; then
            local USER_COLOR="$RED"
        else
            local USER_COLOR="$GREEN"
        fi
        local HOST_COLOR="$CYAN"
        local PRINT_EXIT_STATUS=\
"\$(E=\$?
if [ \$E == 0 ]; then
    echo \"\[$GREEN\][\$E]\[$END_COLOR\]\"
else
    echo \"\[$RED\][\$E]\[$END_COLOR\]\"
fi)"
PS1="\[$USER_COLOR\]\u\[$END_COLOR\]\[$HOST_COLOR\]@\h\[$END_COLOR\] $PRINT_EXIT_STATUS \[$HOST_COLOR\][\$PWD]\[$END_COLOR\]\n\\[$USER_COLOR\]\\$\[$END_COLOR\] "
        PS2="\[$USER_COLOR\]>\[$END_COLOR\] "
    fi
}

set_color

The attachment seems to be broken, so I have posted the snippet above.

Reply via email to