我如何设置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 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 | |
------------------
我是这样做的:
#!/bin/bash
function has-session {
tmux has-session -t name_of_my_session 2>/dev/null
}
if has-session ; then
echo "Session already exists"
else
cd /path/to/my/project
tmux new-session -d -s name_of_my_session 'vim'
tmux split-window -h -p 40 start_web_server
tmux split-window -v
tmux attach-session -d -t name_of_my_session
fi
我的每个项目都有一个文件。你也可以把它们分组,一些用于工作,一些用于业余项目。
也可以将其移动到~/bin文件夹,将其添加到PATH并给出tmux_my_awesome_project名称。然后你就可以在每个地方运行它了。
去https://github.com/remiprev/teamocil看看吧
你可以使用YAML指定你的结构
windows:
- name: sample-window
splits:
- cmd: vim
- cmd:
- ipython
width: 50
- cmd:
height: 25
首先,我有@jasonwryan的方法,但如果你有超过2个配置,它会让人困惑。
所以我创建了一个别名函数:
tmx () {
tmux "$2" source-file "$HOME/.tmux/$1.conf";
}
在~ /。Tmux / I有多个会话用于许多用途。例如,我在不同的公司工作,他们拥有彼此的开发环境。因此,使用上面的alias函数,我可以简单地调用:tmx company1并加载我需要的配置。
更新:tmux命令后的“$2”的目的是,您可以传递额外的tmux参数。
我知道我的解决方案和其他人的很相似,但我找不到任何一个完全符合我的要求的解决方案:
我想在特定的路径上打开标题窗口 我想要尽可能多的窗户和玻璃 我想在每个窗格中运行任意命令,保存在历史记录中 我想要聚焦在脚本末尾的窗口 我希望能快速生成这个 我希望它易于维护
对于我名为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文件执行权限:-) 现在无论在哪里,我都要跑!