我如何设置tmux,使它启动与指定的窗口打开?
当前回答
这个脚本启动一个名为“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
其他回答
这对我很有用。创建5个具有给定名称的窗口,并自动选择到主窗口。
new -n home
neww -n emacs
neww -n puppet
neww -n haskell
neww -n ruby
selectw -t 1
我已经创建了这个脚本。它不需要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
:~$ tmux new-session "tmux source-file ~/session1"
session1
neww
split-window -v 'ipython'
split-window -h
new-window 'mutt'
在.bashrc中创建别名
:~$ echo `alias tmux_s1='tmux new-session "tmux source-file ~/session1"'` >>~/.bashrc
:~$ . ~/.bashrc
:~$ tmux_s1
使用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
推荐文章
- 为什么用反斜杠开始shell命令?
- 遍历带空格的文件列表
- 在Bash中检查传递的参数是否为文件或目录
- 递归复制文件夹,不包括一些文件夹
- 如何在文件中grep不区分大小写的字符串?
- 如何使用文件的行作为命令的参数?
- 如何从命令输出中获得第二列?
- 寻找ALT+LeftArrowKey解决方案在zsh
- 如何做一个非贪婪匹配在grep?
- 在python shell中按方向键时看到转义字符
- Shell命令查找两个文件中的公共行
- 当存储命令输出到变量时,如何保存换行符?
- 如何从shell执行XPath一行程序?
- 如何使用Bash递归创建不存在的子目录?
- 如何将所有子目录中的所有文件压缩成bash中的一个压缩文件