我如何设置tmux,使它启动与指定的窗口打开?


当前回答

这对我很有用。创建5个具有给定名称的窗口,并自动选择到主窗口。

new  -n home
neww -n emacs
neww -n puppet
neww -n haskell
neww -n ruby
selectw -t 1

其他回答

有一个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-continuum将自动保存您的tmux会话,并在下次tmux启动时加载它,应该比这里的一些自定义脚本解决方案更容易设置。

特点: 持续节约tmux环境 当计算机/服务器打开时自动启动tmux tmux启动时自动恢复

要按需保存会话,您可以使用tmux- resurrection插件。运行tmux continuum还需要tmux- resurrection

tmux- resurrection保存tmux环境中的所有小细节 因此,它可以在系统重新启动后(或当您重新启动时)完全恢复 感觉像这样)。无需配置。你应该感觉像你自己 永远不要放弃tmux。

为了简单地打开带有多个窗格的tmux并运行一些命令,我创建了以下bash文件:

#!/bin/bash
tmux split-window -v -p 30 -c ~/path/to/folder1
tmux split-window -h -p 66 -c ~/path/to/folder2
tmux split-window -h -p 50 'mongod'

运行bash文件得到以下内容:

-----------------------------------
|                                 |
|---------------------------------|
|  folder1  | folder2  |  mongod  |
-----------------------------------

你应该在你的tmux配置文件(~/.tmux.conf)中指定它,例如:

new mocp
neww mutt

new -d
neww
neww

(打开一个会话,2个窗口,第一个启动mocp,第二个启动mutt,另一个分离会话,3个空窗口)。

我是这样做的:

#!/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名称。然后你就可以在每个地方运行它了。