gpt4 book ai didi

bash - 如何创建已打开多个窗口的 tmux session ?

转载 作者:行者123 更新时间:2023-12-04 11:56:11 28 4
gpt4 key购买 nike

我已经尝试了几乎可以在网上找到的所有内容,但没有任何效果。我尝试了以下方法,通常的结果是一个只有一个窗口的新 tmux session 。



只需在 .bashrc 中。

.bashrc

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
tmx () {
tmux new-session -A -s SessionName ||
tmux \
neww -s Win1 \; \
neww -s Win2 \; \
neww -s Win3 \; \
neww -s Win4 \; \
selectw -t Win1
}



以下尝试将是我的首选方法,因为它对我来说最有意义。

在没有第一行的情况下调用 tmux 会使所有其他行导致“找不到 session ”错误发生。这是没有意义的,因为我们不应该调用 tmux 来访问这些东西吗?我最初的计划是创建一个 session 并让这个文件自动设置我的 tmux。

.tmux.conf
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
alias tmx='tmux source-file "~/.tmux/mysession"'

.tmux/mysession
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



我究竟做错了什么?

最佳答案

您需要在分离模式下创建 session ( -d );否则,您的脚本会阻塞,直到您与新 session 分离。同样,您的脚本将在 tmux attach-session 之后阻塞直到您分离,因此您需要先选择正确的窗口。请注意,您可以-dnew-window避免让每个新窗口成为当前窗口,无需调用select-window根本。

是的,-d被大量使用。

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
}

关于bash - 如何创建已打开多个窗口的 tmux session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48997929/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com