Background
I use virtualenv
to switch between environments "1.0" and "2.0".
I use screen
to manage terminals.
When I work on one environment I want all new screen
windows to start with this environment.
Question
Can bash instruct screen
to set environment variable on new shell instances, so I could make an alias similar to this one:
alias one='export PRJCT=1.0; screen-magic-setenv PRJCT=1.0; workon 1.0'
alias two='export PRJCT=2.0; screen-magic-setenv PRJCT=2.0; workon 2.0'
and afterwards in ~/.bashrc
call:
[[ -z $PRJCT ]] || workon $PRJCT # switch to project if set
I know I can command screen
to set environment variable on new shells like below but it doesn't help as it won't work in an alias:
:setenv PRJCT
2.0
Best Answer
If I understand correctly, your problem is you cannot find a way to use a shell alias to interact with screen directly. Instead, you can send commands to a running screen using
-X
, includingsetenv
of course, e.g.:The variable is then set, and will be inherited by child shells from that point on, exactly as with
:setenv
. If you use-S
to set sensible distinct session names your task may be easier. The variableSTY
holds the current screen session.If you run just
screen -X setenv PRJCT 2.0
within a screen session, omitting-S
, it will apply to that screen instance.