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


当前回答

使用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以获得完整的解释。

其他回答

这个脚本启动一个名为“e”的会话和三个窗口

#!/bin/sh 
tmux new-session -s e   -n etc -d 'cd /etc; bash -i'
tmux new-window  -t e:1 -n home   'cd ~; bash -i'
tmux new-window  -t e:2 -n log   'cd /var/log; bash -i'

tmux select-window -t e:1
tmux -2 attach-session -t e

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

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

你的屏幕会是这样的:

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

你可以从.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)

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

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

首先,我有@jasonwryan的方法,但如果你有超过2个配置,它会让人困惑。

所以我创建了一个别名函数:

tmx () {
    tmux "$2" source-file "$HOME/.tmux/$1.conf";
}

在~ /。Tmux / I有多个会话用于许多用途。例如,我在不同的公司工作,他们拥有彼此的开发环境。因此,使用上面的alias函数,我可以简单地调用:tmx company1并加载我需要的配置。

更新:tmux命令后的“$2”的目的是,您可以传递额外的tmux参数。