Home » Questions » Computers [ Ask a new question ]

Updating screen session environment variables to reflect new graphical login?

Updating screen session environment variables to reflect new graphical login?

I use linux, and I like to do all my command-line work within a single screen session, so that I can restart my graphical login and such without losing my terminals. However, when I log out and back into my graphical session, this changes all my session environment variables, such as DBus sessions. This means that after logging in again, my screen session now has the old (and wrong) environment variables. So now when I try to start graphical programs from my screen session, at best they emit a warning about not being able to connect to the session bus. At worst, they fail to start completely.

Asked by: Guest | Views: 227
Total answers/comments: 2
Guest [Entry]

"I have implemented a script to do this. You can get it here: github.com/DarwinAwardWinner/screen-sendenv

After putting screen-sendenv.py into your $PATH, you can use the following snippet in your .bashrc:

VARS_TO_UPDATE=""DISPLAY DBUS_SESSION_BUS_ADDRESS SESSION_MANAGER GPG_AGENT_INFO""
screen_pushenv () {
screen-sendenv.py -t screen $VARS_TO_UPDATE
}
tmux_pushenv () {
screen-sendenv.py -t tmux $VARS_TO_UPDATE
}
screen_pullenv () {
tempfile=$(mktemp -q) && {
for var in $VARS_TO_UPDATE; do
screen sh -c ""echo export $var=\$$var >> \""$tempfile\""""
done
. ""$tempfile""
rm -f ""$tempfile""
}
}
tmux_pullenv () {
for var in $VARS_TO_UPDATE; do
expr=""$(tmux showenv | grep ""^$var="")""
if [ -n ""$expr"" ]; then
export ""$expr""
fi
done
}

To use it, just run screen_pushenv before you run screen -r to reattach to your screen session. Then, after attaching with screen -r, you can update the environment in your existing shells with screen_pullenv. The tmux functions accomplish the same thing for tmux, another terminal multiplexer similar to screen."
Guest [Entry]

"I have implemented a script to do this. You can get it here: github.com/DarwinAwardWinner/screen-sendenv

After putting screen-sendenv.py into your $PATH, you can use the following snippet in your .bashrc:

VARS_TO_UPDATE=""DISPLAY DBUS_SESSION_BUS_ADDRESS SESSION_MANAGER GPG_AGENT_INFO""
screen_pushenv () {
screen-sendenv.py -t screen $VARS_TO_UPDATE
}
tmux_pushenv () {
screen-sendenv.py -t tmux $VARS_TO_UPDATE
}
screen_pullenv () {
tempfile=$(mktemp -q) && {
for var in $VARS_TO_UPDATE; do
screen sh -c ""echo export $var=\$$var >> \""$tempfile\""""
done
. ""$tempfile""
rm -f ""$tempfile""
}
}
tmux_pullenv () {
for var in $VARS_TO_UPDATE; do
expr=""$(tmux showenv | grep ""^$var="")""
if [ -n ""$expr"" ]; then
export ""$expr""
fi
done
}

To use it, just run screen_pushenv before you run screen -r to reattach to your screen session. Then, after attaching with screen -r, you can update the environment in your existing shells with screen_pullenv. The tmux functions accomplish the same thing for tmux, another terminal multiplexer similar to screen."