如何从命令行创建多个包含窗口的 tmux 会话 [英] How can I create multiple tmux sessions containing windows from command line

查看:22
本文介绍了如何从命令行创建多个包含窗口的 tmux 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 tmux 为开发会话编写模板脚本.所以我只需要运行这个脚本来打开一个新的开发环境.每个会话将有多个窗口 - 比如说两个.创建分离会话时可以创建第一个窗口(Window1):

I am trying to write a template script for a development session using tmux. So i just need to run this script for opening a new dev environment. Each session will have multiple windows - say two. First window(Window1) can be created while creating the detached session as:

tmux new-session -s $TMUX_SESSION_NAME -d -n Window1(这里 TMUX_SESSION_NAME 是传递给脚本以命名会话的参数).

tmux new-session -s $TMUX_SESSION_NAME -d -n Window1 (Here TMUX_SESSION_NAME is the argument passed to the script to name the session).

但是,如何在同一个会话下创建另一个窗口?

However, how can I create another window under the same session?

请注意,我可以按如下方式创建它,但是在创建另一个会话时会搞砸.虽然 tmux ls 显示每个会话都有 2 个窗口,但第二个会话包含第一个会话的所有 env 设置(两者都用于完全不同的项目)

Note that I can create it as below but that messes up when creating another session. Although tmux ls shows each session having 2 windows each, the second session contains all the env settings of the first session(Both are for completely different projects)

tmux 新窗口 -n Window2tmux attach -t $TMUX_SESSION_NAME

tmux new-window -n Window2 tmux attach -t $TMUX_SESSION_NAME

我怀疑两个/所有会话都在同一个/tmp/tmux-SOME_ID/default 套接字下,因此出现了这个问题.

I suspect both/all sessions go under the same /tmp/tmux-SOME_ID/default socket and hence this problem.

请注意,我第一次开始开发会话时,两个窗口都很好.

Note that the first time i start a dev session all is good with both windows.

有什么想法吗?

推荐答案

TL;DR:可能有类似的东西

TL;DR: probably with something like

tmux new-window -t $TMUX_SESSION_NAME
tmux rename-window -t $TMUX_SESSION_NAME:1 'second'

更多信息(我的配置):

More info (my configuration):

这是我用来开始我的 tmux 会话的内容.该函数的参数将是您要创建的会话的名称.

Here's what I use to start my tmux sessions. The argument to the function would be the name of the session you want to create.

如果这不能回答您的问题,请评论并编辑您的问题,以使我更清楚.

If this does not answer your question, please comment and edit your question to that it is more clear to me.

tmuxstart() {
    tmux new-session -d -s $1 >/dev/null
    tmux rename-window -t $1:0 'main'
    tmux splitw -v -p 10 -t $1:0.0
    tmux splitw -h -p 80 -t $1:0.1
    #required; otherwise pane numbering is bs
    tmux select-pane -t $1:0.0
    tmux splitw -h -p 5 -t $1:0.0
    tmux send-keys -t $1:0.2 'sudo htop' Enter
    tmux send-keys -t $1:0.1 'tmux clock -t $1:0.1' Enter
    tmux select-pane -t $1:0.0
    tmux new-window -t $1
    tmux rename-window -t $1:1 'second'
    tmux splitw -v -p 10 -t $1:1.0
    tmux splitw -h -p 80 -t $1:1.1
    tmux select-pane -t $1:1.0
    tmux splitw -h -p 5 -t $1:1.0
    tmux clock -t $1:1.1
    tmux new-window -t $1
    tmux rename-window -t $1:2 'scratch'
    tmux splitw -v -p 10 -t $1:2.0
    tmux select-pane -t $1:2.0
    tmux splitw -h -p 5 -t $1:2.0
    tmux clock -t $1:2.1
    tmux select-window -t $1:0.0
    tmux a -t $1
}

这篇关于如何从命令行创建多个包含窗口的 tmux 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆