Quantcast
Channel: FedoraForum.org
Viewing all articles
Browse latest Browse all 36167

Fun with PS1

$
0
0
Heyas, just posting because i just finished this.
A kinda of minimalistic approach, as its showing only either a blue $ or a red # which refer to root or user.
The fun part of it is the green happy smiley and the red sad smiley shown at each new prompt, indiciting the success or failure of the last executed comand.


Code:

#
#        Variables
#
        export esc="\033"
        export reset="${esc}[0m"
        PROMPT_COMMAND='RET=$?;'
        RET_VALUE='$(echo $RET)'
#
#        Color
#
        return_color_uid() {
                whitebg="${esc}[47m"
                blackbg="${esc}[40m"
                redfont="${esc}[31m"
                bluefont="${esc}[34m"
                greenfont="${esc}[324m"
                [ 0 -eq $UID ] && echo "${whitebg}${redfont}" || echo "${whitebg}${bluefont}"
        }
        export -f return_color_uid
#
#        Smiley, from other source
#
        RET_SMILEY='$(if [[ $RET = 0 ]]; then echo -ne "\[\033[01;32m\]:)"; else echo -ne "\[\033[01;31m\]:("; fi;)'
#
#        PS1
#
        export PS1="$RET_SMILEY ${reset}\w $(return_color)\\\$${reset} "


To install, simply download the script to your homedir and copy paste the code below into an open terminal screen.
Code:

echo "source ~/prompt-fun.sh" >> ~/.bashrc
Hope you have fun :cool:

EDIT:
Fixed a coloring issue caused by miscoded escape char.

Attached Thumbnails
Click image for larger version

Name:	fun_with_ps1.jpg
Views:	N/A
Size:	31.4 KB
ID:	24913  
Attached Files
File Type: sh prompt-fun.sh (595 Bytes)

Viewing all articles
Browse latest Browse all 36167

Trending Articles