2018-09-21
Setting my bash prompt PS1 to remind me I'm in screen
With some systems constantly running screen and others not I started to get confused. Solution: change the visual indications in the prompt inside screen. I decided to just change the username color in PS1 when I'm in screen. So now:PS1='${STY:+\[\e[1;36m\]}\u${STY:+\[\e[0m\]}@\h:\w\$ 'In bash, ${STY:+..} gives output when shell variable STY is set. So I add the color set/unset commands to the prompt when STY, a typical screen variable is set. The result is dark cyan, a color that works (for me) on my normal light-grey background xterm/putty sessions. Oh, and for root things are different:PS1='\[\e[1;91m\]\u@\h\[\e[0m\]:\w\$ 'Which gives a light red user@hostname. In the above \e causes an escape to be printed. Wrapping parts of the prompt between \[ and \] causes bash to ignore those for counting the length of the prompt so it doesn't get confused on redrawing the prompt when editing the commandline. Samples of colours and other formatting at FLOZz' MISC ยป bash:tip_colors_and_formatting.