我试过了所有我能在网上找到的东西,但都没有用。我尝试了以下方法,通常的结果是一个只有一个窗口的新的tmux会话。
仅在.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会导致出现“会话未找到”错误。这是没有意义的,因为我们不是应该调用tmux来达到这个目的吗?我最初的计划是创建一个会话,并让这个文件自动设置我的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我做错了什么?
发布于 2018-02-27 04:20:46
您需要以分离模式(-d)创建会话;否则,脚本会阻塞,直到您脱离新会话为止。同样,您的脚本将在tmux attach-session之后阻塞,直到分离为止,因此您需要首先选择正确的窗口。请注意,您可以使用-d和new-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
}https://stackoverflow.com/questions/48997929
复制相似问题