[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: auto connect to screen and open a new shell?

From: Trent W. Buck
Subject: Re: auto connect to screen and open a new shell?
Date: Wed, 22 Oct 2008 15:40:28 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Nils <address@hidden> writes:

> i open op a new terminal, which the opens my shell (zsh). I want the
> zsh to check if it is already inside of a screen session, and if it is
> not, to connect to one, and open a new shell in there.

I have almost that for sh:

    ### ~/.profile: sourced by bourne-compatible login shells.
    ### If ~/.bash_profile exists, this will NOT be read by bash!
    ### SUS bookmark:

    # [unrelated code elided.]

    ## The naive "chsh -s /usr/bin/screen" breaks scp (and other things).
    ## Have sh start screen automatically "when appropriate".  That is,
    ## 1) not in a screen window (STY);
    ## 2) stdin is a tty;
    ## 3) screen is installed; and
    ## 4) terminal is capable of displaying screen.
    ## Replace "$STY" with "$STY$SSH_CLIENT$SSH_ORIGINAL_COMMAND" to avoid
    ## nesting screens when sshing (untested).
    test -z "$STY" -a -t 0 &&
    { type screen && tput clear && tput cup && ! tput hc && ! tput os
    } 2>/dev/null >&2 &&          # ignore boring, expected error messages
        ## Set the window title to the host name.
        ## Note that using echo -e \e for ^[ is not portable.
        type uname >/dev/null 2>&1 &&
        test -n "${HOSTNAME:=`uname -n`}" &&
        case "$TERM" in
            screen*) printf %bk%s%b%b \\033 "${HOSTNAME%%.*}" \\033 \\0134;;
        ## If new session, start agents.
        screen -ls | grep -i 'No Sockets found' >/dev/null 2>&1 &&
        eval "$(twb-agents)"
        ## Start screen.
        exec screen -DRR

    ## If execution reaches this point, screen isn't the login shell.  In
    ## that case, if this is a bash shell, it's a good idea to do the
    ## bashisms in .bashrc.
    test -n "$BASH" &&
    test -f ~/.bashrc &&
    . ~/.bashrc

> essentially i would like i to do a screen -x, C-a c. I check if i am
> inside a shell with the STY variable, but i have not found a good way
> to connect while creating a new shell

I'm not sure if you can do exactly that.  I suppose it depends if you're
starting xterm from within the screen session, or from some other X
client.  When STY is set you can just do "screen foo" and it'll pop up a
new window running foo inside the screen session.  Otherwise you might
be able to do something like "screen -X screen && screen -xRR" to first
start a new window, *then* connect to the session.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]