Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: updating the shell environment in screen (was Re: prompt and ssh)




On 25.05.2009, at 00:26, Wayne Davison wrote:

On Thu, May 21, 2009 at 09:41:03AM +0200, Vincent Lefevre wrote:
3. Later, log on the machine directly (without ssh) and recall the
  screen session. SSH_CONNECTION is still set (as the environment
  doesn't change in the recalled shell)

Here's what I do to ensure that my screen sessions always have updated
environment info:

In my ~/.zshrc file:

alias scr=' ~/bin/update_screenenv; screen -R -d -i'
function preexec {
   [ -e ~/.screenenv ] && . ~/.screenenv
   # ... among other things ...
}

The ~/bin/update_screenenv script:

#!/bin/zsh
for var in SSH_AUTH_SOCK SSH_AGENT_PID DISPLAY WINDOWID SSH_TTY SSH_CLIENT SSH_CONNECTION SESSION_MANAGER; do
   if [[ -n "${(P)var}" ]]; then
	echo "export $var='${(P)var}'"
   else
	echo "unset $var"
   fi
done >~/.screenenv

What this does for me is to update the ~/.screenenv file every time I
connect to my screen session (which I always do via my 'scr' alias).
Since my shells all source the ~/.screenenv file before every command,
the environment stays updated with the info from the latest parent shell
that connected to screen.

What happens if you do not use screen? .screenenv is still sourced before every command. Doesn't this lead to confusion? How do you detect that you're inside screen?

For the latter I think something like "if [[ $TERM == screen-bce ]]" would be okay, but far from perfect.


Sebastian



Messages sorted by: Reverse Date, Date, Thread, Author