次のように単純なtmux confを作成したいと思います。
- 水平に分割されたウィンドウ/ウィンドウ/whatever_stupid_terminology(hsplit)
- トップウィンドウで開く
tail -f foo
- 下のウィンドウで開く
tail -f bar
tmuxでどうすればいいですか?
これが私が持っているものです。
#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf
考えられる解決策は考えられません。だから私はそれがすべて間違っていることを知っています。最も直感的ではないconfファイルの1つ
ベストアンサー1
必要なものを達成するための迅速で簡単なコマンドラインは次のとおりです。
$ tmux new-session -s asdf -n myWindow -d 'tail -f foo'\; \
split-window -d 'tail -f bar'\; attach-session
このソリューションにはいくつかの欠点があります。
スケーラビリティが悪い(コマンドがさらに追加され、結果を理解するのが難しい)。
2つのtailコマンドはインタラクティブシェルでは実行されないため、2つのコマンドを終了するとウィンドウが
myWindow
破棄されます(セッションが作成されない場合はウィンドウがセッションとともに破棄されます)。
以下は、試した方法で動作するシェルスクリプトです。私の目標を達成する方法について考えることは常に最も簡単です。手動その後、tmux コマンドに変換します。これは最も簡単でクリーンなアプローチではありませんが、通常は次のように機能します。
#!/bin/sh
# create a new session. Note the -d flag, we do not want to attach just yet!
tmux new-session -s asdf -n 'myWindow' -d
# send 'tail -f foo<enter>' to the first pane.
# I address the first pane using the -t flag. This is not necessary,
# I'm doing it so explicitly to show you how to do it.
# for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j
# split the window *vertically*
tmux split-window -v
# we now have two panes in myWindow: pane 0 is above pane 1
# again, specifying pane 1 with '-t 1' is optional
tmux send-keys -t 1 'tail -f bar' C-j
# uncomment the following command if you want to attach
# explicitly to the window we just created
#tmux select-window -t asdf:mywindow
# finally attach to the session
tmux attach -t asdf
試してもコマンドと設定の構文が気に入らない場合は、次のtmux
点を検討してください。tmuxatorシンプルでより透明な構文を使用してtmuxセッションを管理できるRuby gemです。
私の答えにXサーバーなしで複数の端末を同時に使用するtmux
役に立つリソースへのリンクを見つけることができます