我如何设置tmux,使它启动与指定的窗口打开?
当前回答
这个脚本启动一个名为“e”的会话和三个窗口
#!/bin/sh
tmux new-session -s e -n etc -d 'cd /etc; bash -i'
tmux new-window -t e:1 -n home 'cd ~; bash -i'
tmux new-window -t e:2 -n log 'cd /var/log; bash -i'
tmux select-window -t e:1
tmux -2 attach-session -t e
其他回答
有一个tmux插件。
查看tmux- resurrection
Restore tmux environment after system restart. Tmux is great, except when you have to restart the computer. You lose all the running programs, working directories, pane layouts etc. There are helpful management tools out there, but they require initial configuration and continuous updates as your workflow evolves or you start new projects. tmux-resurrect saves all the little details from your tmux environment so it can be completely restored after a system restart (or when you feel like it). No configuration is required. You should feel like you never quit tmux.
或tmux-continuum
特点: 持续节约tmux环境 当计算机/服务器打开时自动启动tmux tmux启动时自动恢复
我试着用了这一页上的所有想法,但没有一个我喜欢。我只是想要一个解决方案,当我的终端打开时,用一组特定的窗口启动tmux。我还希望它是幂等的,即打开一个新的终端窗口接管tmux会话从前一个。
上面的解决方案通常倾向于打开多个tmux会话,而我只想要一个。首先,我把这个添加到我的~/.bash_profile中:
tmux start-server
if [[ -z "$TMUX" ]]
then
exec tmux attach -d -t default
fi
然后我在我的~/.tmux.conf中添加了以下内容:
new -s default -n emacs /usr/local/bin/emacs
neww -n shell /usr/local/bin/bash
neww -n shell /usr/local/bin/bash
selectw -t 1
现在,每当我启动一个终端或启动tmux或其他什么,我要么重新连接到我现有的所需设置(名为default的会话),要么用该设置创建一个新会话。
这对我很有用。创建5个具有给定名称的窗口,并自动选择到主窗口。
new -n home
neww -n emacs
neww -n puppet
neww -n haskell
neww -n ruby
selectw -t 1
如果你只是想把屏幕分成2个窗格(水平),你可以运行这个命令(不需要tmux或shell脚本):
tmux new-session \; split-window -h \;
你的屏幕会是这样的:
[ks@localhost ~]$ │[ks@localhost ~]$
│
│
│
│
│
│
│
│
│
│
│
[10] 0:ks@localhost:~* "localhost.localdomain" 19:51 31-янв-16
tmuxp支持JSON或YAML会话配置和python API。一个用YAML语法创建新会话的简单tmuxp配置文件是:
session_name: 2-pane-vertical
windows:
- window_name: my test window
panes:
- pwd
- pwd