Updating $DISPLAY automatically (was: Newbie questions)

Johan Svedberg <[email protected]> Thu, 25 Mar 2004 23:08:43 +0100
Newsgroups gmane.comp.gnu.screen
Message-ID <[email protected]>
* Mar 25 20:35 [email protected] <[email protected]>:

[...]

> 1. It appears that the DISPLAY variable gets messed up when I detach
> my screen window at work, re-attach it at home, and then
> detach/re-attach it once more at work.  After doing this, X-apps no
> longer show (they don't crash either; I assume the are being sent to
> never-never land).
>
>    One further complication is that at work I access my Linux account
>    (the one in which I run screen) through a Windows2000 workstation +
>    PuTTY + an Exceed X server.  (Exceed may be part of this problem.)
>
>    Does anybody know how can I straighten out the DISPLAY?

I wrote this kludge for bash to get it done automatically:

# Create ssh environment file which are used in the prompt_command()
function
if [ -e $HOME/.screen/environment ]; then
    `which rm` -rf ~/.screen/environment
fi

if [ -n "$DISPLAY" ]; then
    echo "DISPLAY=$DISPLAY" > $HOME/.screen/environment
fi

if [ -n "$SSH_AUTH_SOCK" ]; then
    echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $HOME/.screen/environment
fi

if [ -n "$SSH_CLIENT" ]; then
    echo "SSH_CLIENT=\"$SSH_CLIENT\"" >> $HOME/.screen/environment
else if [ -n "$SSH_CONNECTION" ]; then
    echo "SSH_CONNECTION=\"$SSH_CONNECTION\"" >> $HOME/.screen/environment
fi
fi

# Function to be executed as PROMPT_COMMAND
function prompt_command()
{
    if [ "$TERM" = "screen" ]; then
        . $HOME/.screen/environment
        export DISPLAY SSH_AUTH_SOCK SSH_CLIENT SSH_CONNECTION
    fi
}

export PROMPT_COMMAND=prompt_command

-- 
Johan Svedberg, [email protected], http://johan.svedberg.pp.se/


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/gnu-screen/

<*> To unsubscribe from this group, send an email to:
     [email protected]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/