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

Re: prompt and ssh



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.

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.



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