Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: prompt and ssh
- X-seq: zsh-users 14158
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: prompt and ssh
- Date: Fri, 22 May 2009 03:08:50 +0200
- In-reply-to: <090521092207.ZM14221@xxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <e7db6e960905190954j7be72739p6b521bca8e90fe7f@xxxxxxxxxxxxxx> <20090519200217.35368.qmail@xxxxxxxxxxx> <20090521074103.GN27141@xxxxxxxxxxxxxxxxxxx> <090521092207.ZM14221@xxxxxxxxxxxxxxxxxxxxxx>
On 2009-05-21 09:22:07 -0700, Bart Schaefer wrote:
> On May 21, 9:41am, Vincent Lefevre wrote:
> } Subject: Re: prompt and ssh
> }
> } On 2009-05-20 08:02:16 +1200, Atom Smasher wrote:
> } > you can test for SSH_CONNECTION, SSH_CLIENT, or SSH_TTY on the far side.
> } > i would recommend SSH_CONNECTION.
> }
> } But this will not work well if you use "screen".
>
> Depending on the platform you're on ...
>
> if grep -q $SSH_CONNECTION[(w)1]\:$SSH_CONNECTION[(w)2] =(netstat -na)
> then
> print Using SSH_CONNECTION: $SSH_CONNECTION
> else
> print Invalid SSH_CONNECTION
> fi
>
> This "fails" only if you disconnect from screen but leave ssh connected.
This won't work in my case, because I sometimes do the following:
1. On my machine at home, start ssh connections to my machine at work.
2. Start screen remotely.
3. Detach the screen session.
4. Resume the screen session at work (but the ssh connections started
in (1) are still there).
I also do the following:
1. Start screen remotely (via ssh).
2. Detach the screen session.
3. Resume the screen session from a different ssh connection (e.g.
because the first one has died -- BTW, this is even one of the
reasons of using screen).
> Figuring out what the correct values should be and passing them to the
> in-screen shell is another matter. The suggestion of a wrapper for
> screen that writes a file, combined with checking the file contents in
> the precmd or preexec hooks, might do it. E.g.:
>
> screen() {
> typeset -pm SSH_\* > ~/.screen_SSH
> screen "$@"
> }
> screen_ssh_precmd() {
> source ~/.screen_SSH
> }
> precmd_functions+=(screen_ssh_precmd)
>
> That is probably a bit too simple -- you could check the file mod time
> to avoid sourcing it unnecessarily, and it'd probably be wise check that
> you own the file and no one else can write to it or to the directory
> it's in, etc.
One should also find a way to make it work with several screen
sessions (in screen, that can be identified by $STY, so that the
filename could be based on it). When starting a new screen, the
SSH_* environment variables are inherited, so that nothing special
needs to be done. When resuming a screen session, one should detect
which one, and use a filename corresponding to this session. When
screen terminates, one should check if the session still exists
(attached or detached), and if it isn't, remove the file.
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author