WHATS THIS:
Colored Bash Prompt
NOTE: for colors there are two ways to add it to the prompt (tput and the long brackets way). First of the prompt is managed by how the PS1 environment variable is set at the current session. If PS1=”fred:” then you would see fred: before every prompt. There are codes that you can put in that the bash shell analyzes as certain commands for example “PS1=\u:” will put your username in the shell prompt like so koss:. Back to the colors subject, tput only gives you 8 colors and brackets gives you more, same end result different way of achieving it – as all things linux.
 
HOW TO USE:
 
1) Log in to your Linux
 
2) Note what it is now
 # echo PS1
 
3) Backup PS1
# export PS1bak=$PS1
# echo $PS1 > ~/.oldps1
 
4) Set the PS1 to one of the ones below (For example the first one – try the other PS1s from below, this example one is very simple)
PS1=”$(tput setaf 1)\u$(tput sgr0)$(tput setaf 2)@$(tput sgr0)$(tput setaf 3)\h:$(tput sgr0)”
 
5) If you want it to be permament you need to put it into the script that runs when the system loads
 
Go to home directory
# cd ~
 
# ls -lisah
 
Look for .bashrc
Edit it
 
# vim .bashrc
 
Start inserting into text
Hit the “i” key
 
Scroll down with the arrow keys and type out or paste(right click with mouse in CLI window to paste)
PS1=”$(tput setaf 1)#\u$(tput setaf 2)@$(tput setaf 3)\h:$(tput setaf 2)\w$(tput setaf 6)#$(tput setaf 5)~~$(tput setaf 6)\d$(tput setaf 5)~~$(tput setaf 6)\@$(tput setaf 5)~$(tput setaf 2)\t$(tput setaf 5)~HIST:\!~CMD:\#\$\n$(tput sgr0)”
 
Then hit “escape” key and type “:wq!” that will save and exit
Now relog in and check out what you have for a prompt
 
(OPTIONAL RESTORING) 
 
# PS1=$PS1bak
 
Or (if rebooted since changed the PS1 as long as you backed up your PS1 into a file earlier then this next step will work)
 
These ` signs below are “back-ticks” [above the Tab key, Shift+Tidle (Shift+~) gets the ` sign]
# PS1=`cat .oldps1`
And dont forget to remove the entry from ~/.bashrc
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
COOL 1:

PS1=”#\u@\h:\w#~~\d~~\@~\A~\$\n”

GREEN – complex
PS1=”\\[$(tput setaf 2)\\]\\u@\\h:\\w #\\[$(tput sgr0)\\]”
RED – complex
PS1=”\\[$(tput setaf 1)\\]\\u@\\h:\\w #\\[$(tput sgr0)\\]”
SIMPLER GREEN
PS1=”$(tput setaf 2)simple:$(tput sgr0)”
SIMPLER RED
PS1=”$(tput setaf 1)simple:$(tput sgr0)”
RASTA
PS1=”$(tput setaf 1)\u$(tput sgr0)$(tput setaf 2)@$(tput sgr0)$(tput setaf 3)\h:$(tput sgr0)”
COOL:
PS1=”#\u@\h:\w#~~\d~~\@~\A~\$\n”
AWESOME1 –  (by Kossboss)
PS1=”$(tput setaf 1)#\u$(tput sgr0)$(tput setaf 2)@$(tput sgr0)$(tput setaf 3)\h:$(tput sgr0)$(tput setaf 2)\w$(tput sgr0)$(tput setaf 2)#$(tput sgr0)$(tput setaf 2)~~\d~~\@~\t~\$\n$(tput sgr0)”
AWESOME1a – (by Kossboss)
PS1=”$(tput setaf 1)#\u$(tput setaf 2)@$(tput setaf 3)\h:$(tput setaf 2)\w$(tput setaf 6)#$(tput setaf 5)~~$(tput setaf 6)\d$(tput setaf 5)~~$(tput setaf 6)\@$(tput setaf 5)~$(tput setaf 2)\t$(tput setaf 5)~HIST:\!~CMD:\#\$\n$(tput sgr0)”
 
Here is a screen show of AWESOME1a
 
 
[update: 1/28/2013]
 
found a really good one so I had to highlight it
 
AWESOME PS1 found online:
 
# https://bbs.archlinux.org/viewtopic.php?pid=1068202#p1068202
 
PS1=”\[\033[0;37m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \”[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\”)[$(if [[ ${EUID} == 0 ]]; then echo ‘\[\033[0;31m\]\h’; else echo ‘\[\033[0;33m\]\u\[\033[0;37m\]@\[\033[0;96m\]\h’; fi)\[\033[0;37m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;37m\]]\n\[\033[0;37m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]”
 
[update: 1/28/2013 : – later on in the day]
– found online – I only edited the highlighted one below and the one above it
 
These ones are nice they change based on time of day, how many files in the current directory, current command number in history, how many active jobs, etc.
PS1=”\[\e[32;1m\](\[\e[37;1m\]\u\[\e[32;1m\])-(\[\e[37;1m\]jobs:\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])\n(\[\[\e[37;1m\]! \!\[\e[32;1m\])-> \[\e[0m\]”
PS1=”\n\[\e[30;1m\]\[\016\]\[\017\](\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n\[\016\]\[\017\](\[\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ‘s: ::g’) files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ‘s/total //’)b\[\e[30;1m\])-> \[\e[0m\]”
 
PS1=”\[\e[30;1m\]\[\016\]\[\017\](\[\e[31;1m\]\u@\h\[\e[30;1m\])-(\[\e[31;1m\]\j\[\e[30;1m\])-(\[\e[31;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n\[\016\]\[\017\](\[\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ‘s: ::g’) files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ‘s/total //’)b\[\e[30;1m\])-> \[\e[0m\]”
 
PS1=’\[\e[1;32m\]\u@\H:\[\e[m\] \[\e[1;37m\]\w\[\e[m\]\n\[\e[1;33m\]hist:\! \[\e[0;33m\] \[\e[1;31m\]jobs:\j \$\[\e[m\] ‘
 
PS1=”[\[\033[32m\]\w]\[\033[0m\]\n\[\033[1;36m\]\u\[\033[1;33m\]-> \[\033[0m\]”
 
PS1=”\[\033[35m\]\t\[\033[m\]-\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ “
 
PS1=”\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e ‘s:/dev/::’): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ‘s: ::g’) files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ‘s/total //’)b\[\033[0m\] -> \[\033[0m\]”

 

Leave a Reply

Your email address will not be published. Required fields are marked *