首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建已打开多个窗口的tmux会话?

如何创建已打开多个窗口的tmux会话?
EN

Stack Overflow用户
提问于 2018-02-26 22:09:55
回答 1查看 4.1K关注 0票数 4

我试过了所有我能在网上找到的东西,但都没有用。我尝试了以下方法,通常的结果是一个只有一个窗口的新的tmux会话。

仅在.bashrc中。

.bashrc

代码语言:javascript
复制
tmx () {
    tmux new-session -A -s SessionName
    tmux new-window -n Win1
    tmux new-window -n Win2
    tmux new-window -n Win3
    tmux new-window -n Win4
    tmux attach-session -d -t SessionName # with and without this line
    tmux select-window -t Win1 # with and without this line
}

再一次只在.bashrc。

.bashrc

代码语言:javascript
复制
tmx () {
    tmux new-session -A -s SessionName ||
    tmux \
        neww -s Win1 \; \
        neww -s Win2 \; \
        neww -s Win3 \; \
        neww -s Win4 \; \
        selectw -t Win1
}

下面的尝试将是我最喜欢的方法,因为它对我来说最有意义。

在不使用第一行的情况下调用tmux会导致出现“会话未找到”错误。这是没有意义的,因为我们不是应该调用tmux来达到这个目的吗?我最初的计划是创建一个会话,并让这个文件自动设置我的tmux。

.tmux.conf

代码语言:javascript
复制
new-session -A -s SessionName
new-window -t Win1
new-window -t Win2
new-window -t Win3
new-window -t Win4
attach-session -d -t SessionName # with and without this line
select-window -t Win1 # with and without this line

这种方法,无论是使用别名还是创建函数,通常都会导致“连接服务器失败”。但是,当摆弄到足以避免这种情况发生时,它就会产生与其他人相同的结果。

.bashrc

代码语言:javascript
复制
alias tmx='tmux source-file "~/.tmux/mysession"'

. .tmux/mysession

代码语言:javascript
复制
new-session -A -s SessionName
new-window -t Win1
new-window -t Win2
new-window -t Win3
new-window -t Win4
attach-session -d -t SessionName # with and without this line
select-window -t Win1 # with and without this line

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-27 04:20:46

您需要以分离模式(-d)创建会话;否则,脚本会阻塞,直到您脱离新会话为止。同样,您的脚本将在tmux attach-session之后阻塞,直到分离为止,因此您需要首先选择正确的窗口。请注意,您可以使用-dnew-window来避免使每个新窗口成为当前窗口,从而完全不必调用select-window

是的,-d经常被使用。

代码语言:javascript
复制
tmx () {
    # Use -d to allow the rest of the function to run
    tmux new-session -d -s SessionName
    tmux new-window -n Win1
    # -d to prevent current window from changing
    tmux new-window -d -n Win2
    tmux new-window -d -n Win3
    tmux new-window -d -n Win4
    # -d to detach any other client (which there shouldn't be,
    # since you just created the session).
    tmux attach-session -d -t SessionName
}
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48997929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档