我如何设置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启动时自动恢复

其他回答

tmuxp支持JSON或YAML会话配置和python API。一个用YAML语法创建新会话的简单tmuxp配置文件是:

session_name: 2-pane-vertical
windows:
  - window_name: my test window
    panes:
      - pwd
      - pwd

创建新会话时,可以使用tmux钩子执行命令。具体来说,这是使用会话创建的钩子实现的。

例如,你可以在~/.tmux.conf文件中添加以下代码,将屏幕分成三部分,top在右下角运行:

set-hook -g session-created 'split -h ; split -v top'

这种方法的优点是,您不必以任何特殊的方式(即shell脚本或别名)运行tmux来获得所需的结果。您还可以将其与tmux new-session -A -s mysession结合使用,这样钩子命令只在您第一次创建会话时运行,而不是在后续的附件上运行。

该功能是由d15d54c2c在2016年添加的。包含它的第一个发行版是2.4。

去https://github.com/remiprev/teamocil看看吧

你可以使用YAML指定你的结构

windows:
  - name: sample-window
    splits:
      - cmd: vim
      - cmd:
        - ipython
        width: 50
      - cmd:
        height: 25

使用tmuxinator—它允许您配置多个会话,并且您可以在任何给定时间选择启动哪个会话。您可以在特定的窗口或窗格中启动命令,并为窗口指定标题。下面是一个开发Django应用程序的例子。

配置文件示例:

# ~/.tmuxinator/project_name.yml
# you can make as many tabs as you wish...

project_name: Tmuxinator
project_root: ~/code/rails_project
socket_name: foo # Not needed. Remove to use default socket
rvm: 1.9.2@rails_project
pre: sudo /etc/rc.d/mysqld start
tabs:
  - editor:
      layout: main-vertical
      panes:
        - vim
        - #empty, will just run plain bash
        - top
  - shell: git pull
  - database: rails db
  - server: rails s
  - logs: tail -f logs/development.log
  - console: rails c
  - capistrano:
  - server: ssh me@myhost

请参阅上面链接的README以获得完整的解释。

从我的“得到”。脚本,我每天早上都会调用它来运行一堆后续的“get”。XXX”的任务来刷新我跟踪的软件。有些是自动退出。其他的则需要在get完成后进行更多的交互(比如请求构建emacs)。

#!/bin/sh
tmux att -t get ||
tmux \
  new -s get -n capp \; \
  send-keys 'get.capp' C-m \; \
  neww -n emacs \; \
  send-keys 'get.emacs' C-m \; \
  neww -n git \; \
  send-keys 'get.git' C-m \; \
  neww -n mini \; \
  send-keys 'get.mini' C-m \; \
  neww -n port \; \
  send-keys 'get.port' C-m \; \
  neww -n rakudo \; \
  send-keys 'get.rakudo' C-m \; \
  neww -n neil \; \
  send-keys 'get.neil && get.neil2 && exit' C-m \; \
  neww -n red \; \
  send-keys 'get.red && exit' C-m \; \
  neww -n cpan \; \
  send-keys 'get.cpan && exit' C-m \; \
  selectw -t emacs