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

其他回答

您可以编写一个小型shell脚本,用所需的程序启动tmux。我在一个称为dev-tmux的shell脚本中有以下内容。开发环境:

#!/bin/sh
tmux new-session -d 'vim'
tmux split-window -v 'ipython'
tmux split-window -h
tmux new-window 'mutt'
tmux -2 attach-session -d

所以每次我想启动我最喜欢的开发环境时,我都可以这样做

$ dev-tmux

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

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

从我的“得到”。脚本,我每天早上都会调用它来运行一堆后续的“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

有一个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启动时自动恢复

我已经创建了这个脚本。它不需要tmuxinator, ruby或其他。它只是一个bash脚本,可配置:

一个名为config的文件应该包含如下内容:

combo=()
combo+=('logs' 'cd /var/log; clear; pwd')
combo+=('home' 'cd ~; clear; pwd')

bash代码应该是:

#!/bin/bash

if [ -r config ]; then
    echo ""
    echo "Loading custom file"
    . config
else
    . config.dist
fi

tmux start-server

window=0
windownumber=-1

for i in "${combo[@]}"; do

    if [ $((window%2)) == 0 ]; then
        name=${i}
        ((windownumber++))
    else
        command=${i}
    fi

    if [ ${combo[0]} == "${i}" ]; then
        tmux new-session -d -s StarTmux -n "${name}"
    else
        if [ $((window%2)) == 0 ]; then
            tmux new-window -tStarTmux:$windownumber -n "${name}"
        fi
    fi

    if [ $((window%2)) == 1 ]; then
        tmux send-keys -tStarTmux:$windownumber "${command}" C-m
    fi

    ((window++))
done

tmux select-window -tStarTmux:0
tmux attach-session -d -tStarTmux