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

Re: Is zsh buggy in connection with screen?



On Tue, Nov 08, 2005 at 03:13:17PM +0100, Vincent Lefevre wrote:
> What is your terminal? xterm for instance sets environment variables
> that are no longer valid in a different terminal and/or X11 session:

I use screen too, and have implemented some environment variable
"tunneling" to ensure that the inner shells get their environment
updated.  What I did is to write a shell script named "update_screenenv"
that writes out a set of environment-updating commands into a file named
~/.screenenv.  I then alias my normal screen-startup command (which
happens to be the alias "scr") to run this command before starting
screen:

    alias scr=' ~/bin/update_screenenv; screen -R -d -i'

Finally, I define a preexec function in my .zshrc, but only when the
TERM is "screen*", so that the inner shells source this file (my preexec
command also does other things, but I've removed them for clarity):

    case "$TERM" in
    screen*)
	function preexec {
	    . ~/.screenenv
	}
	;;
    xterm*)
	# ... etc. ...
	;;
    *)
	# ... etc. ...
	;;
    esac

Using this causes the inner zsh environments to get updated from the
outer environment that was present when screen was re-attached.

My update script looks like this (yeah, it's ugly, but it works):

    #!/bin/zsh
    cat >~/.screenenv <<EOT
    export SSH_AUTH_SOCK=$SSH_AUTH_SOCK
    EOT
    if [[ -n "$SSH_AGENT_PID" ]]; then
	export SSH_AGENT_PID=$SSH_AGENT_PID >>~/.screenenv
    else
	echo "unset SSH_AGENT_PID" >>~/.screenenv
    fi
    if [[ -n "$DISPLAY" ]]; then
	echo "export DISPLAY=$DISPLAY" >>~/.screenenv
    else
	echo "unset DISPLAY" >>~/.screenenv
    fi
    if [[ -n "$WINDOWID" ]]; then
	echo "export WINDOWID=$WINDOWID" >>~/.screenenv
    else
	echo "unset WINDOWID" >>~/.screenenv
    fi
    if [[ -n "$SSH_TTY" ]]; then
	cat >>~/.screenenv <<EOT
    export SSH_CLIENT="$SSH_CLIENT"
    export SSH_CONNECTION="$SSH_CONNECTION"
    export SSH_TTY=$SSH_TTY
    EOT
    else
	echo "unset SSH_CLIENT SSH_CONNECTION SSH_TTY" >>~/.screenenv
    fi
    if [[ -n "$SESSION_MANAGER" ]]; then
	echo "export SESSION_MANAGER=$SESSION_MANAGER" >>~/.screenenv
    else
	echo "unset SESSION_MANAGER" >>~/.screenenv
    fi

..wayne..



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