我如何设置tmux,使它启动与指定的窗口打开?
当前回答
有一个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.conf)中指定它,例如:
new mocp
neww mutt
new -d
neww
neww
(打开一个会话,2个窗口,第一个启动mocp,第二个启动mutt,另一个分离会话,3个空窗口)。
我知道我的解决方案和其他人的很相似,但我找不到任何一个完全符合我的要求的解决方案:
我想在特定的路径上打开标题窗口 我想要尽可能多的窗户和玻璃 我想在每个窗格中运行任意命令,保存在历史记录中 我想要聚焦在脚本末尾的窗口 我希望能快速生成这个 我希望它易于维护
对于我名为johndoe的项目,我创建了一个johndoe.conf文件,它本质上是一个bash脚本,在我的配置(~/.config/tmux/tmux-sessions/johndoe.conf)的某处。
这个文件很容易维护,因为它不像我在其他答案中看到的那样有无数的\ everywhere:
# Create a new session named johndoe, with a first window named Main
# at the specified starting path.
# The -d is for detached mode, which allows me to continue defining the rest of the session
# before attaching to it. Without -d, tmux would open the client right away and
# ignore the rest of the session definition
tmux new -d -s johndoe -n 'Main' -c ~/dev/own/johndoe
# Simulate the user entering some docker command in the first window available
# in the target session named (-t) johndoe
tmux send -t johndoe 'docker compose up -d' Enter
# Create a new window in the target session, with the title 'UI run'
tmux neww -t pers -n 'UI run' -c ~/dev/own/johndoe/front-end
# Simulate user entering a command to the first pane
tmux send -t pers:'UI run.0' 'git status --short' Enter
# Split this window horizontally
tmux split-window -t pers:'UI run' -h -c ~/dev/own/johndoe/front-end
# Simulate user entering a command to the second pane in this window
tmux send -t pers:'UI run.1' 'npm run dev' Enter
tmux neww -t johndoe -n 'API run' -c ~/dev/own/johndoe/back-end/Api
tmux send -t johndoe:'API run' 'dotnet run --no-build' Enter
# Focus the first window
tmux select-window -t johndoe:'Main'
# Attach the current terminal to the only session available
# (you might want to add "-t johndoe" here if you need several sessions running in parallel)
tmux a -d
我创建了一个bash/zsh别名来源会话配置:
alias tmuxjohndoe='. ~/.config/tmux/tmux-sessions/johndoe.conf'
我花了适量的调试时间,弄清楚我需要给johndo .conf文件执行权限:-) 现在无论在哪里,我都要跑!
去https://github.com/remiprev/teamocil看看吧
你可以使用YAML指定你的结构
windows:
- name: sample-window
splits:
- cmd: vim
- cmd:
- ipython
width: 50
- cmd:
height: 25
我试图创建一个复杂的窗格网格,不得不一遍又一遍地处理切换和分割窗格。以下是我的体会:
tmux new-session \;
让你开始新的疗程。要将其水平或垂直分割,请使用split-window -h或-v,如下所示:
tmux new-session \; split-window -v \; split-window -h \;
创建3个窗格,如下所示:
------------
| |
|----------|
| | |
------------
要在该窗格中运行命令,只需添加发送键'my-command'命令和执行命令的C-m:
tmux new-session \; \
send-keys 'tail -f /var/log/monitor.log' C-m \; \
split-window -v \; \
split-window -h \; \
send-keys 'top' C-m \;
结果会话应该是这样的。
------------
| tail |
|----------|
| | top |
------------
现在,我再次尝试细分左下角的窗格,因此可以使用last-pane返回,或者在更复杂的窗口中,使用select-pane -t 1,其中1是按从0开始创建的顺序创建的窗格的编号。
tmux new-session \; \
send-keys 'tail -f /var/log/monitor.log' C-m \; \
split-window -v \; \
split-window -h \; \
send-keys 'top' C-m \; \
select-pane -t 1 \; \
split-window -v \; \
send-keys 'weechat' C-m \;
这是否。基本上你只需要知道如何使用分割窗口和选择窗格。通过-p 75传递拆分窗口创建的窗格的百分比大小也很方便,这样可以更好地控制窗格的大小。
tmux new-session \; \
send-keys 'tail -f /var/log/monitor.log' C-m \; \
split-window -v -p 75 \; \
split-window -h -p 30 \; \
send-keys 'top' C-m \; \
select-pane -t 1 \; \
split-window -v \; \
send-keys 'weechat' C-m \;
是什么导致会话看起来像这样
------------------
| tail |
|----------------|
| | top |
|----------| |
| weechat | |
------------------
如果你只是想把屏幕分成2个窗格(水平),你可以运行这个命令(不需要tmux或shell脚本):
tmux new-session \; split-window -h \;
你的屏幕会是这样的:
[ks@localhost ~]$ │[ks@localhost ~]$
│
│
│
│
│
│
│
│
│
│
│
[10] 0:ks@localhost:~* "localhost.localdomain" 19:51 31-янв-16