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

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



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.

..wayne..



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