如何在不附加到会话的情况下创建 tmux window?
How to create tmux window without attaching to the session?
我希望能够在名为 'scratch' 运行 的会话中创建一个新的 tmux window(tab) 自定义命令(即 'ping www.google.com' ) 而不附加到会话。如果 'scratch' 不存在,我也希望创建它。
shell 脚本将如何编写?
从 中抄袭并做了一些改动,这是一个例子:
TMUX_SESSION_NAME='scratch'
tmux new-session -d -s $TMUX_SESSION_NAME >/dev/null
tmux new-window -t $TMUX_SESSION_NAME
tmux send-keys -t $TMUX_SESSION_NAME:1.0 'ping www.google.com' Enter
更多信息(我的配置):
这是我用来启动我的 tmux 会话的。该函数的参数将是您要创建的会话的名称。
如果这不能回答您的问题,请评论并编辑您的问题,使我更清楚。
tmuxstart() {
tmux new-session -d -s >/dev/null
tmux rename-window -t :0 'main'
tmux splitw -v -p 10 -t :0.0
tmux splitw -h -p 80 -t :0.1
#required; otherwise pane numbering is bs
tmux select-pane -t :0.0
tmux splitw -h -p 5 -t :0.0
tmux send-keys -t :0.2 'sudo htop' Enter
tmux send-keys -t :0.1 'tmux clock -t :0.1' Enter
tmux select-pane -t :0.0
tmux new-window -t
tmux rename-window -t :1 'second'
tmux splitw -v -p 10 -t :1.0
tmux splitw -h -p 80 -t :1.1
tmux select-pane -t :1.0
tmux splitw -h -p 5 -t :1.0
tmux clock -t :1.1
tmux new-window -t
tmux rename-window -t :2 'scratch'
tmux splitw -v -p 10 -t :2.0
tmux select-pane -t :2.0
tmux splitw -h -p 5 -t :2.0
tmux clock -t :2.1
tmux select-window -t :0.0
tmux a -t
}
我希望能够在名为 'scratch' 运行 的会话中创建一个新的 tmux window(tab) 自定义命令(即 'ping www.google.com' ) 而不附加到会话。如果 'scratch' 不存在,我也希望创建它。
shell 脚本将如何编写?
从
TMUX_SESSION_NAME='scratch'
tmux new-session -d -s $TMUX_SESSION_NAME >/dev/null
tmux new-window -t $TMUX_SESSION_NAME
tmux send-keys -t $TMUX_SESSION_NAME:1.0 'ping www.google.com' Enter
更多信息(我的配置):
这是我用来启动我的 tmux 会话的。该函数的参数将是您要创建的会话的名称。
如果这不能回答您的问题,请评论并编辑您的问题,使我更清楚。
tmuxstart() {
tmux new-session -d -s >/dev/null
tmux rename-window -t :0 'main'
tmux splitw -v -p 10 -t :0.0
tmux splitw -h -p 80 -t :0.1
#required; otherwise pane numbering is bs
tmux select-pane -t :0.0
tmux splitw -h -p 5 -t :0.0
tmux send-keys -t :0.2 'sudo htop' Enter
tmux send-keys -t :0.1 'tmux clock -t :0.1' Enter
tmux select-pane -t :0.0
tmux new-window -t
tmux rename-window -t :1 'second'
tmux splitw -v -p 10 -t :1.0
tmux splitw -h -p 80 -t :1.1
tmux select-pane -t :1.0
tmux splitw -h -p 5 -t :1.0
tmux clock -t :1.1
tmux new-window -t
tmux rename-window -t :2 'scratch'
tmux splitw -v -p 10 -t :2.0
tmux select-pane -t :2.0
tmux splitw -h -p 5 -t :2.0
tmux clock -t :2.1
tmux select-window -t :0.0
tmux a -t
}