* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 19:54 how can I invoke zsh via screen when logged in via ssh? TJ Luoma
@ 2014-01-22 21:22 ` Simon Ruderich
2014-01-22 23:48 ` TJ Luoma
2014-01-23 6:49 ` Dirk Heinrichs
2014-01-23 6:20 ` nyuszika7h
` (4 subsequent siblings)
5 siblings, 2 replies; 11+ messages in thread
From: Simon Ruderich @ 2014-01-22 21:22 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 2256 bytes --]
On Wed, Jan 22, 2014 at 02:54:02PM -0500, TJ Luoma wrote:
> 1) Would 'zsh' function normally when in screen(1) ?
Hello,
Of course. I use zsh almost exclusively from within GNU screen.
> 2) I've already noticed that emacs keys don't seem to work right, i.e.
> control+a does not jump to the beginning of the line, although
> control+e jumps to the end of the line. Should I make some adjustment
> to `bindkeys` or anything else?
GNU screen uses Ctrl-a as "prefix" for all its commands. To send
a "real" Ctrl-a to the process running in the screen window, use
Ctrl-a a.
> 3) What's the 'best' way to invoke screen(1) from .zshenv ? I
> already have this:
>
> [...]
This looks a little fragile. To check for a SSH session use one
of the SSH_* variables set by sshd, e.g. SSH_CONNECTION or
SSH_CLIENT.
if [[ -n $SSH_CONNECTION ]]; then
# inside a SSH session
fi
> So I was going to change it to:
>
> [snip]
>
> which would, I believe, resume an existing `screen` session if one
> existed, but would otherwise just launch `screen` anew.
My current solution to automatically launch a GNU screen session
or connect to a running one looks like this:
if [[ $TERM != dumb && $TERM != linux && -z $STY && -z $TMUX ]]; then
# Get running detached sessions.
session=$(screen -list | grep 'Detached' | awk '{ print $1; exit }')
# Create a new session if none is running.
if [[ -z $session ]]; then
exec screen
# Reattach to a running session.
else
exec screen -r $session
fi
fi
This must be added to the ~/.zshrc on the server.
You can easily adapt this for your setup. Just change the
condition inside [[ ... ]] to something like
[[ -n $SSH_CONNECTION && -z $STY && -z $TMUX ]]
This condition is true if inside a ssh connection and neither GNU
screen nor tmux is already running.
> ps - bonus question: anyone know how to tell screen(1) to _not_ show
> its welcome message every time it launches?
man screen ;-)
Add "startup_message off" to your ~/.screenrc.
Regards
Simon
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 21:22 ` Simon Ruderich
@ 2014-01-22 23:48 ` TJ Luoma
2014-01-23 6:49 ` Dirk Heinrichs
1 sibling, 0 replies; 11+ messages in thread
From: TJ Luoma @ 2014-01-22 23:48 UTC (permalink / raw)
To: Zsh-Users List
On Wed, Jan 22, 2014 at 4:22 PM, Simon Ruderich <simon@ruderich.org> wrote:
> man screen ;-)
>
> Add "startup_message off" to your ~/.screenrc.
Bah! *kicks self*
I _had_ read (well, "visually scanned") `man screen` but had been
looking for things like 'hushlogin' or 'suppress' not something as
straightforward as "startup".
Thanks for the tips, I'll definitely give them a try!
(Thanks also to nyuszika7h who replied off-list).
TjL
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 21:22 ` Simon Ruderich
2014-01-22 23:48 ` TJ Luoma
@ 2014-01-23 6:49 ` Dirk Heinrichs
1 sibling, 0 replies; 11+ messages in thread
From: Dirk Heinrichs @ 2014-01-23 6:49 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 843 bytes --]
Am 22.01.2014 22:22, schrieb Simon Ruderich:
>> 2) I've already noticed that emacs keys don't seem to work right, i.e.
>> > control+a does not jump to the beginning of the line, although
>> > control+e jumps to the end of the line. Should I make some adjustment
>> > to `bindkeys` or anything else?
> GNU screen uses Ctrl-a as "prefix" for all its commands. To send
> a "real" Ctrl-a to the process running in the screen window, use
> Ctrl-a a.
I've remapped this to Ctrl-o in .screenrc:
escape ^Oo
Bye...
Dirk
--
*Dirk Heinrichs*, Senior Systems Engineer, Engineering Solutions
*Recommind GmbH*, Von-Liebig-Straße 1, 53359 Rheinbach
*Tel*: +49 2226 1596666 (Ansage) 1149
*Email*: dhs@recommind.com <mailto:dhs@recommind.com>
*Skype*: dirk.heinrichs.recommind
www.recommind.com <http://www.recommind.com>
http://www.recommind.com
[-- Attachment #2.1: Type: text/html, Size: 1684 bytes --]
[-- Attachment #2.2: Logo.gif --]
[-- Type: image/gif, Size: 1537 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 19:54 how can I invoke zsh via screen when logged in via ssh? TJ Luoma
2014-01-22 21:22 ` Simon Ruderich
@ 2014-01-23 6:20 ` nyuszika7h
2014-01-24 6:12 ` Kurtis Rader
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: nyuszika7h @ 2014-01-23 6:20 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 30 bytes --]
I replied off-list? Fail. >_>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 19:54 how can I invoke zsh via screen when logged in via ssh? TJ Luoma
2014-01-22 21:22 ` Simon Ruderich
2014-01-23 6:20 ` nyuszika7h
@ 2014-01-24 6:12 ` Kurtis Rader
2014-01-24 12:40 ` Richard Hartmann
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Kurtis Rader @ 2014-01-24 6:12 UTC (permalink / raw)
To: TJ Luoma; +Cc: Zsh-Users List
[-- Attachment #1: Type: text/plain, Size: 2960 bytes --]
I strongly recommend using tmux rather than screen. It has a much saner
configuration language and is more powerful. It also correctly handles
terminals which support 256 colors. I wrote a pair of scripts for work that
wraps around ssh and tmux (and iTerm2 for Mac OS X). This allows me to type
work attach
to create iTerm2 windows appropriately sized and positioned and attach each
to its corresponding tmux session on the remote host. If the tmux session
isn't already running one is created. It also takes care of ensuring the
DISPLAY environment variable is set appropriately to allow X11 based apps
to display on my local system.
It also supports a bunch of other commands, For example, "work list" to
enumerate existing tmux sessions. Or "work ssh" to get a raw ssh session.
If there's interest I can work on removing my employer specific bits (which
deal with managing a VPN tunnel).
On Wed, Jan 22, 2014 at 11:54 AM, TJ Luoma <luomat@gmail.com> wrote:
> I use zsh as my login shell for several accounts I connect to via ssh.
>
>
> My connection to these accounts is often fragile, either because they
> were initiated on an iOS device or behind a satellite internet
> connection.
>
>
> I had a thought today that perhaps one answer would be to use
> 'screen(1)' as my login shell for those accounts, but then I realized
> that I didn't want that to be the shell I use for local logins, just
> for SSH logins.
>
>
> I wondered if anyone had already done this, so I didn't have to
> re-invent the wheel, or might have some experience with potential
> problems that I might run into when doing this.
>
>
> 1) Would 'zsh' function normally when in screen(1) ?
>
>
> 2) I've already noticed that emacs keys don't seem to work right, i.e.
> control+a does not jump to the beginning of the line, although
> control+e jumps to the end of the line. Should I make some adjustment
> to `bindkeys` or anything else?
>
>
> 3) What's the 'best' way to invoke screen(1) from .zshenv ? I already have
> this:
>
>
> PPID_NAME=$(command ps -o 'command=' -cp ${PPID} 2>/dev/null )
>
>
> case "${PPID_NAME}" in
>
> sshd)
>
> SSH=yes
>
> ;;
>
>
> launchd)
>
> LAUNCHD=yes
>
> ;;
>
>
> esac
>
>
> So I was going to change it to:
>
>
>
> PPID_NAME=$(command ps -o 'command=' -cp ${PPID} 2>/dev/null )
>
>
> case "${PPID_NAME}" in
>
> sshd)
>
> exec =screen -r || exec =screen
>
> ;;
>
>
> launchd)
>
> LAUNCHD=yes
>
> ;;
>
>
> esac
>
>
> which would, I believe, resume an existing `screen` session if one
> existed, but would otherwise just launch `screen` anew.
>
>
> Is there a better way?
>
>
> Thanks in advance,
>
>
> TjL
>
>
>
>
> ps - bonus question: anyone know how to tell screen(1) to _not_ show
> its welcome message every time it launches?
>
--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 19:54 how can I invoke zsh via screen when logged in via ssh? TJ Luoma
` (2 preceding siblings ...)
2014-01-24 6:12 ` Kurtis Rader
@ 2014-01-24 12:40 ` Richard Hartmann
2014-01-24 16:23 ` Axel Beckert
2014-01-24 19:50 ` Christoph (Stucki) von Stuckrad
2014-01-24 14:20 ` lilydjwg
2014-01-25 17:51 ` Thorsten Kampe
5 siblings, 2 replies; 11+ messages in thread
From: Richard Hartmann @ 2014-01-24 12:40 UTC (permalink / raw)
To: TJ Luoma; +Cc: Zsh-Users List
If you have a flakey connection, have a look at mosh[1]; using this
instead of ssh on my laptop has been nothing but great.
Richard
[1] http://mosh.mit.edu/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-24 12:40 ` Richard Hartmann
@ 2014-01-24 16:23 ` Axel Beckert
2014-01-24 19:50 ` Christoph (Stucki) von Stuckrad
1 sibling, 0 replies; 11+ messages in thread
From: Axel Beckert @ 2014-01-24 16:23 UTC (permalink / raw)
To: Zsh-Users List
Hi,
On Fri, Jan 24, 2014 at 01:40:52PM +0100, Richard Hartmann wrote:
> If you have a flakey connection, have a look at mosh[1]; using this
> instead of ssh on my laptop has been nothing but great.
Besides Mosh there's also AutoSSH[2] in case you need port forwarding
and other stuff in combination with automatic SSH reconnects.
[2] http://www.harding.motd.ca/autossh/
But both are not available for iOS AFAIK.
On Thu, Jan 23, 2014 at 10:12:29PM -0800, Kurtis Rader wrote:
> I strongly recommend using tmux rather than screen.
I don't. (SCNR)
> It also correctly handles terminals which support 256 colors.
GNU Screen works fine for me with 256 colors for many years now.
(Other people claim they're getting eye-cancer from my 256-color mutt
running inside my main Screen session. :-)
Kind regards, Axel
--
/~\ Plain Text Ribbon Campaign | Axel Beckert
\ / Say No to HTML in E-Mail and News | abe@deuxchevaux.org (Mail)
X See http://www.nonhtmlmail.org/campaign.html | abe@noone.org (Mail+Jabber)
/ \ I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-24 12:40 ` Richard Hartmann
2014-01-24 16:23 ` Axel Beckert
@ 2014-01-24 19:50 ` Christoph (Stucki) von Stuckrad
1 sibling, 0 replies; 11+ messages in thread
From: Christoph (Stucki) von Stuckrad @ 2014-01-24 19:50 UTC (permalink / raw)
To: zsh-users
On Fri, 24 Jan 2014, Richard Hartmann wrote:
> If you have a flakey connection, have a look at mosh[1]; using this
> instead of ssh on my laptop has been nothing but great.
...
> [1] http://mosh.mit.edu/
Definitely right! Since 'mosh' exists, working with a laptop
from different places on the same surviving connection (on
screen of course) is a lot easier than before. :-)
Except if the laptop reboots, for which you still ned screen.
But, may be the answer to the original Subject, is as simple as:
If you have the wrong login-shell and can not change it,
you eighter set the SHELL Variable in your startup files,
or you put 'shell /usr/bin/zsh' into your '~/.screenrc'.
In both cases all Screen-Windows run with 'zsh'.
Stucki
--
Christoph von Stuckrad * * |nickname |Mail <stucki@mi.fu-berlin.de> \
Freie Universitaet Berlin |/_*|'stucki' |Tel(Mo.,Mi.):+49 30 838-75 459|
Mathematik & Informatik EDV |\ *|if online| (Di,Do,Fr):+49 30 77 39 6600|
Takustr. 9 / 14195 Berlin * * |on IRCnet|Fax(home): +49 30 77 39 6601/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 19:54 how can I invoke zsh via screen when logged in via ssh? TJ Luoma
` (3 preceding siblings ...)
2014-01-24 12:40 ` Richard Hartmann
@ 2014-01-24 14:20 ` lilydjwg
2014-01-25 17:51 ` Thorsten Kampe
5 siblings, 0 replies; 11+ messages in thread
From: lilydjwg @ 2014-01-24 14:20 UTC (permalink / raw)
To: zsh-users; +Cc: TJ Luoma
On Wed, Jan 22, 2014 at 02:54:02PM -0500, TJ Luoma wrote:
> I use zsh as my login shell for several accounts I connect to via ssh.
>
>
> My connection to these accounts is often fragile, either because they
> were initiated on an iOS device or behind a satellite internet
> connection.
>
>
> I had a thought today that perhaps one answer would be to use
> 'screen(1)' as my login shell for those accounts, but then I realized
> that I didn't want that to be the shell I use for local logins, just
> for SSH logins.
>
>
> I wondered if anyone had already done this, so I didn't have to
> re-invent the wheel, or might have some experience with potential
> problems that I might run into when doing this.
So you might be interested in mosh[1] (the mobile shell), which I find
is great for slow unstable connections.
[1]: http://mosh.mit.edu/
> [...]
--
Best regards,
lilydjwg
Linux Vim Python 我的博客:
http://lilydjwg.is-programmer.com/
--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how can I invoke zsh via screen when logged in via ssh?
2014-01-22 19:54 how can I invoke zsh via screen when logged in via ssh? TJ Luoma
` (4 preceding siblings ...)
2014-01-24 14:20 ` lilydjwg
@ 2014-01-25 17:51 ` Thorsten Kampe
5 siblings, 0 replies; 11+ messages in thread
From: Thorsten Kampe @ 2014-01-25 17:51 UTC (permalink / raw)
To: zsh-users
* TJ Luoma (Wed, 22 Jan 2014 14:54:02 -0500)
> I had a thought today that perhaps one answer would be to use
> 'screen(1)' as my login shell for those accounts, but then I realized
> that I didn't want that to be the shell I use for local logins, just
> for SSH logins.
That's pretty much the same way I use it.
> I wondered if anyone had already done this, so I didn't have to
> re-invent the wheel, or might have some experience with potential
> problems that I might run into when doing this.
>
>
> 3) What's the 'best' way to invoke screen(1) from .zshenv ? I
> already have this:
> [...]
>
> which would, I believe, resume an existing `screen` session if one
> existed, but would otherwise just launch `screen` anew.
Why don't you simply read the man page and invoke screen with the
right options?! Would have saved you tons of time...
I suggest you replace all your ssh calls like "ssh user@host" with
"ssh -t user@host screen -xRR ssh". That creates a session with name
"ssh" or connect to an already running session with that name.
Thorsten
^ permalink raw reply [flat|nested] 11+ messages in thread