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"
fi
Code 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"
fi
Code language: PHP (php)
And remember, if you’re asking yourself if you should run something in a screen, you’re already too late!
Leave a Reply