I had seen some really awesome BASH prompts a few months ago and decided it was time to buckle down and "pimp my prompt". I have to say that I'm VERY happy with how it turned out!
gedit ~/.bashrc
- comment out the lines that start with "PS1="
from
PS1=blahblahblah
to
#PS1=blahblahblah - Copy/paste the code below into your .bashrc
hostn=$(hostname -s)
usern=$(whoami)
#black="\e[0;30m"
#lgreen="\e[32;1m"
#white="\e[1;37m"
#lgray="\e[1;30m"
#lgray="\e[1;32m"
#dgray="\e[1;30m"
#uwhite="\e[4;37;1m"
#uwhite="\e[37m"
#ublack="\e[4;30m"
userc="\[\e[1;30m\]"
timec="\[\e[1;30m\]"
typec="\[\e[1;30m\]"
dirc="\[\e[1;30m\]"
nc="\[\e[0m\]"
function prompt {
ctime=$(date +%R)
prmpt="-[${usern}@${hostn}][${PWD}][${ctime}]"
cols=$(tput cols)
let FILLS=${cols}-${#prmpt}
LINE=""
if [[ "$PWD" =~ "/home/$usern" ]]
then
let FILLS=$FILLS+5+${#usern}
fi
for (( f=0; f<$FILLS; f++ )) do LINE=$LINE"\e(0q\e(B" done PS1="$nc\[\e(0l\e(B\]<$userc\u$nc@$userc\h$nc><$dirc\w$nc>${LINE}<$timec${ctime}$nc>\n"
PS1=$PS1"\[\e(0\]m\[\e(B\]<$typec\$$nc>\[\e(0\]q\[\e(B\]<" } PROMPT_COMMAND=prompt
TIP: If you hack this up, try to put as much of the code OUTSIDE the function {} as possible to reduce the time it takes your terminal to render the prompt.


1 comments:
nice post. it helped me to set prompt to what I wanted.
Post a Comment