How can I make GNU screen run a command or script every time I create a new window?

StackOverflow https://stackoverflow.com/questions/20785625

  •  21-09-2022
  •  | 
  •  

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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top