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

Re: how can I invoke zsh via screen when logged in via ssh?



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: signature.asc
Description: Digital signature



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