Friday, May 23, 2014

BASH PS1 modification for screen

I use screen a lot, so it can be confusing when switching between separate screen instances. I often use it remotely, and used to accidentally make the mistake of using CTRL - A - D (to detach from screen session) too many times, and the final time CTRL - D is registered by BASH, which terminates my remote session connection.

Instead: always know where you are! Modify PS1 in ~/.bashrc (it might work, and be more appropriate, to put it in ~/.screenrc )

if [ $TERM = screen ]
then
    PS1="(screen ${STY#*.}) $PS1"

fi;

The string substitution bit is just there to remove the process ID from the PID.screen_name $STY variable

Demo:

nick@machine:~$ screen -S project2
(screen project2) nick@machine:~$





No comments:

Post a Comment