欠落している場合にのみ特定の名前で新しいtmuxウィンドウを開きます。

欠落している場合にのみ特定の名前で新しいtmuxウィンドウを開きます。

同じセッション内の独自のtmuxウィンドウで複数のコマンドを並列に実行して、各コマンドのインスタンスを1つだけ実行するようにする必要があります。

理想的には、ウィンドウは簡単に識別できるように固定名と順序に従う必要があります。

私は過去に次のようなことをしたと思います。

tmux new-window -t cmd1 -n cmd1 { my command }

その後、tmuxは最後のセッションで最初に名前が付けられたcmd1場所(cmd2などが続く)にウィンドウを作成したり、ウィンドウがすでに存在する場合は何もしません。

ベストアンサー1

実際の整数をインデックスとして使用すると、私に適しています。

$ tmux new-window -t 1 -n cmd1 -d sleep 60
$ tmux new-window -t 1 -n cmd1 -d sleep 60
create window failed: index in use: 1

整数以外のインデックスの場合は機能しません。

$ tmux new-window -t cmd1 -n cmd1 -d sleep 60
can't find window i1

マニュアルページの引用(tmux 2.5-4):

 new-window [-adkP] [-c start-directory] [-F format] [-n window-name] [-t target-window] [shell-command]
               (alias: neww)
         Create a new window.  With -a, the new window is inserted at the next index up from the specified target-window, moving windows up if necessary, otherwise target-window is the new window location.

         If -d is given, the session does not make the new window the current window.  target-window represents the window to be created; if the target already exists an error is shown, unless the -k flag is used, in which case it is destroyed.

おすすめ記事