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


当前回答

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

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

其他回答

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

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

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

我是这样做的:

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

你可以从.tmux.conf文件中获取不同的会话,如下所示:

# initialize sessions
bind S source-file ~/.tmux/session1 
bind s source-file ~/.tmux/session2

然后按照你的要求设置会议的格式:

#session1
new  -s SessionName -n WindowName Command
neww -n foo/bar foo
splitw -v -p 50 -t 0 bar
selectw -t 1 
selectp -t 0

这将打开2个窗口,其中第二个窗口将命名为foo/bar,并将垂直分为两半(50%),foo运行在bar之上。焦点将在窗口2 (foo/bar),顶部窗格(foo)。

然后,您可以使用PrefixShifts启动首选的tmux会话(在本例中为session1)

如果你只是想把屏幕分成2个窗格(水平),你可以运行这个命令(不需要tmux或shell脚本):

tmux new-session \; split-window -h \;

你的屏幕会是这样的:

[ks@localhost ~]$                      │[ks@localhost ~]$ 
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
[10] 0:ks@localhost:~*                  "localhost.localdomain" 19:51 31-янв-16

我已经创建了这个脚本。它不需要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