Quick Tip: Add Screen Name to Bash Prompt

I often SSH into servers to get some work done, and one of the things I discovered recently is that I may not always know or remember if I’m in a screen session.

So I had the bright idea to just add it to my shell prompt!

Simply just add one of these to your RC file of choice:

Bash

# Add Screen name to PS1 if we're in a screen.
if [ -n "$STY" ]; then
	PS1="\[\e[1m\](Screen: $STY)\[\e[0m\]\n$PS1"
fiCode language: PHP (php)

ZSH

# Add Screen name to PROMPT if we're in a screen.
if [[ -n "$STY" ]]; then
	PROMPT="%B(Screen: $STY)%b"$'\n'"$PROMPT"
fiCode language: PHP (php)

And remember, if you’re asking yourself if you should run something in a screen, you’re already too late!

Other Posts Not Worth Reading

Hey, You!

Like this kind of garbage? Subscribe for more! I post like once a month or so, unless I found something interesting to write about.