Question

I'm trying to write a script that makes GNU screen call virtualenvwrapper's workon command to jump to an existing virtualenv based on the screen session name.

I've managed to make it work when the session starts, but I want to be able to run commands everytime a window is created, and I can't find hooks or anything similar to it.

Does screen allow a way to run commands everytime a window is created within a session?

Was it helpful?

Solution

Try putting the logic into your ~/.profile (if using the deflogin on setting) or ~/.mkshrc (or similar, depending on your shell) file. Something like this:

if test -n "$STY"; then
        # we are inside GNU screen
        screenpid=${STY%%.*}
        screenname=${STY#*.}
        # do your magic
fi

In this scenario, $screenname will contain either the name passed to the -S option of GNU screen, or something like ttyp0.shorthostname or pts-9.shorthostname (depending on the OS) if -S was not used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top