Gnu画面でタブウィンドウを開き、各タブウィンドウでコマンドを実行する方法

Gnu画面でタブウィンドウを開き、各タブウィンドウでコマンドを実行する方法

セッションを開始するときは、以下のように名前を付けてください。screen -S name1

GNOME端末でタブを開くときと同じように、この画面セッションでタブウィンドウを開きたいです。

gnome-terminal --tab -e "some commands"

だから何をしますか?

ベストアンサー1

1. 画面のタブ

.screenrcファイルに次のコンテンツを追加しようとしています。

screen -t tab1
screen -t tab2

ステータスバーなどを起動するのに役立つ良いデフォルトの.screenrcがあります。メモ:通常はホームディレクトリにあります/home/<username>/.screenrc

screen -t validate #rtorrent
screen -t compile #irssi
screen -t bash3
screen -t bash4
screen -t bash5
altscreen on
term screen-256color
bind ',' prev
bind '.' next
#
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'

スクリーンショット

スクリーンセッションss

2. 画面のタブ(内部的にコマンド実行)

次の例では、.screenrc2つのタブを作成し、各タブで3つのechoコマンドを実行します。

screen -t tab1                                                                                     
select 0                                                                                           
stuff "echo 'tab1 cmd1'; echo 'tab1 cmd2'; echo 'tab1 cmd3'^M"                                     
screen -t tab2                                                                                     
select 1                                                                                           
stuff "echo 'tab2 cmd1'; echo 'tab2 cmd2'; echo 'tab2 cmd3'^M"                                     

altscreen on                                                                                       
term screen-256color                                                                               
bind ',' prev                                                                                      
bind '.' next                                                                                      
#                                                                                                  
#change the hardstatus settings to give an window list at the bottom of the                        
#screen, with the time and date and with the current window highlighted                            
hardstatus alwayslastline                                                                          
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'              
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'

この技術は、画面selectstuffコマンドを利用して最初にタブの1つを選択し、そのタブに文字列を「埋めます」。

スクリーンショット

タブとコマンド付き画面SS

3. ファイル生成を使用しない # .screenrc2

次のことができるシナリオを探している場合:

  1. スクリーンセッションの作成
  2. タブとして読み込む
  3. 各タブで独自のコマンドを実行できるようにする
  4. .screenrc書類は必要ありません

もしそうなら、これはあなたのためです!しかし、準備してください。コマンドラインを使用するのは少し難しいかもしれません。

まず、スクリーンセッションを作成しましょう。

$ screen -AdmS myshell -t tab0 bash

このスイッチは-AdmS次のことを行います。

(よりスクリーンマニュアルページ詳しくは)

-ㅏ

    Adapt the sizes of all windows to the size of the  current terminal. 
    By default, screen tries to restore its old window sizes when
    attaching to resizable terminals

-DM

    Start screen in "detached" mode. This creates a new session but
    doesn't attach to it. This is useful for system startup scripts.

-Sセッション名

    When creating a new session, this option can be used to specify a
    meaningful name for the session. This name identifies the session for
    "screen -list" and "screen -r" actions. It substitutes the default
    [tty.host] suffix.

次に、タブとそのコマンドを使用してロードを開始します。

$ screen -S myshell -X screen -t tab1 vim
$ screen -S myshell -X screen -t tab2 ping www.google.com
$ screen -S myshell -X screen -t tab3 bash

この3つのコマンドは3つの追加タブを作成し、vimを実行し、googleでpingを実行し、bashシェルを起動します。画面セッションを一覧表示すると、次の情報が表示されます。

$ screen -ls
There is a screen on:
        26642.myshell   (Detached)
1 Socket in /var/run/screen/S-root.

スクリーンセッションに接続すると、私の殻をクリックして埋め込みタブを一覧表示すると、次のようになります。

$ screen -r myshell

このキーの組み合わせを押してください。Ctrl+A次にShift+"

Num Name                                                                   Flags

  0 tab0                                                                       $
  1 tab1                                                                       $
  2 tab2                                                                       $
  3 tab3                                                                       $

に切り替えるタブ2:

64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=443 ttl=55 time=41.4 ms
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=444 ttl=55 time=33.0 ms
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=445 ttl=55 time=30.1 ms

スクリーンショット

CLIで起動した画面SS

上記のコマンドは、OPが追求することを達成する基本的な方法です。もちろん、これはBashエイリアスまたはシェルスクリプトを使用して圧縮および改善することができます。これは単に機能を示し、方向を示すためのものです!

引用する

おすすめ記事