zsh-users
 help / color / mirror / code / Atom feed
From: Simon Ruderich <simon@ruderich.org>
To: zsh-users@zsh.org
Subject: Re: how can I invoke zsh via screen when logged in via ssh?
Date: Wed, 22 Jan 2014 22:22:45 +0100	[thread overview]
Message-ID: <20140122212244.GA20502@ruderich.org> (raw)
In-Reply-To: <CADjGqHsv+YdBYp7Q7Enp0kcmTWk_45AYKvzraFWyB4Y5YLdg0A@mail.gmail.com>

[-- 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 --]

  reply	other threads:[~2014-01-22 21:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-22 19:54 TJ Luoma
2014-01-22 21:22 ` Simon Ruderich [this message]
2014-01-22 23:48   ` TJ Luoma
2014-01-23  6:49   ` Dirk Heinrichs
2014-01-23  6:20 ` nyuszika7h
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140122212244.GA20502@ruderich.org \
    --to=simon@ruderich.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).