Rotating prompt color

If one has more that one terminal window opened, it’s sometimes hard to tell what is where. Here is example of the file ~/.bash_profile, which is always executed, if new terminal window is opened. Numeric value of the previous prompt is saved in the file ps1-color.num. Script also defines environment variable _TERM_START with value set to the start time and it can be helpfull to identify terminal window as well.

#date command is in back-ticks
export _TERM_START=date +"%a_%Y-%m-%d_%H:%M:%S"
export PS1COLOR=34

input=”/home/joedoe/.bash_sessions/ps1_color.num”
IFS= read -r PS1COLOR < “$input”
PS1COLOR=$(expr ${PS1COLOR} + 1)
if (( $PS1COLOR > 37 ))
then
PS1COLOR=30
fi

echo ${PS1COLOR} > $input
export PS1=”\[033[1;${PS1COLOR}m\]\h \W \$ \[\033[0;30m\]”

This entry was posted in workday. Bookmark the permalink.

Leave a Reply