Hello fellow free software users!. I want to share with you a small snippet that I have in my .bashrc to make a custom prompt, as you can see in the attached image. It is licensed under the GNU General Public License version 3 or any later and you will find it attached to this post. Note that the exit status code of the previous command is displayed between the host name and the path.

I am also writing to ask for your help to raise funds for the legal defense of a friend who is currently in jail. He is known as Alina Davis among Russian users for his sometimes feminine and sometimes androgynous appearance and sense of fashion You can find information about Alina and how to help in this web site. Please help by donating, and also by linking to our fund-raising web site from your social media accounts. For those of you who use Facebook or Twitter, please help us by linking to Alina's fund raising web site from those social networks, especially among those groups that may sympathize with Alina's situation. Thanks.


# 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 <http://www.gnu.org/licenses/>.

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

Reply via email to