Gnu-Screen: Run script that sends commands to the screen session it is being run in

前端 未结 5 2090
半阙折子戏
半阙折子戏 2020-12-31 17:39

Is it possible to write a script to change the name and turn on monitoring for the current tab assuming that it is being run in screen?

Thanks.

相关标签:
5条回答
  • 2020-12-31 17:54

    Screen declares $STY environment variable, you can try use it.

    0 讨论(0)
  • 2020-12-31 18:06

    Are you looking to display information or interact with the screen session itself? You can send messages back with this: (http://www.slac.stanford.edu/comp/unix/package/epics/extensions/iocConsole/screen.1.html#lbAI)

    THE MESSAGE LINE Screen displays informational messages and other diagnostics in a message line. While this line is distributed to appear at the bottom of the screen, it can be defined to appear at the top of the screen during compilation. If your terminal has a status line defined in its termcap, screen will use this for displaying its messages, otherwise a line of the current screen will be temporarily overwritten and output will be momentarily interrupted. The message line is automatically removed after a few seconds delay, but it can also be removed early (on terminals without a status line) by beginning to type.

    The message line facility can be used by an application running in the current window by means of the ANSI Privacy message control sequence. For instance, from within the shell, try something like:

    echo '<esc>^Hello world from window '$WINDOW'<esc>\\' 
    

    where '' is an escape, '^' is a literal up-arrow, and '\' turns into a single backslash.

    0 讨论(0)
  • 2020-12-31 18:06

    Screen runs transparently, so detecting the screen session is hard. If you try sending key presses, that would work, and would fill your terminal with a tiny bit of junk if you're not in a session.

    0 讨论(0)
  • 2020-12-31 18:07

    I think this works:

    if [-n "$STY"]; then
        screen -X title "foo"
        screen -X monitor on
    fi
    
    0 讨论(0)
  • 2020-12-31 18:14

    From the screen manpage:

      -X   Send the specified command to a running screen  session.  You  can
           use  the  -d or -r option to tell screen to look only for attached
           or detached screen sessions. Note that this command  doesn't  work
           if the session is password protected.
    

    Basically, run

    screen -X title mynewtitle
    screen -X monitor on
    

    If the terminal is not running within screen, it silently errors:

    notinscreen:~$ screen -X title mynewtitle
    notinscreen:~$
    

    You can also send the command to a specific session, even while detached. Given a screen session named "main":

    $ screen -S main
    [detach from screen session]
    $ screen -ls
    There is a screen on:
            2073.main       (Detached)
    1 Socket in /tmp/uscreens/S-dbr.
    

    ..you can sent the title of the last-active window to blah:

    $ screen -x main -X title blah
    

    ..or a specific window (named oldwindow in this example):

    $ screen -x main -p oldwindow -X title blah
    

    Instead of using -x main you can use the process ID (from screen -ls), also instead of using a window name (-p oldwindow) you can use a window number:

    $ screen -x 2073 -p 0 -X title h
    

    If there is only one session, you do not have to specify the session PID or name.

    0 讨论(0)
提交回复
热议问题