我如何设置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
其他回答
我试着用了这一页上的所有想法,但没有一个我喜欢。我只是想要一个解决方案,当我的终端打开时,用一组特定的窗口启动tmux。我还希望它是幂等的,即打开一个新的终端窗口接管tmux会话从前一个。
上面的解决方案通常倾向于打开多个tmux会话,而我只想要一个。首先,我把这个添加到我的~/.bash_profile中:
tmux start-server
if [[ -z "$TMUX" ]]
then
exec tmux attach -d -t default
fi
然后我在我的~/.tmux.conf中添加了以下内容:
new -s default -n emacs /usr/local/bin/emacs
neww -n shell /usr/local/bin/bash
neww -n shell /usr/local/bin/bash
selectw -t 1
现在,每当我启动一个终端或启动tmux或其他什么,我要么重新连接到我现有的所需设置(名为default的会话),要么用该设置创建一个新会话。
插件tmux-continuum将自动保存您的tmux会话,并在下次tmux启动时加载它,应该比这里的一些自定义脚本解决方案更容易设置。
特点: 持续节约tmux环境 当计算机/服务器打开时自动启动tmux tmux启动时自动恢复
要按需保存会话,您可以使用tmux- resurrection插件。运行tmux continuum还需要tmux- resurrection
tmux- resurrection保存tmux环境中的所有小细节 因此,它可以在系统重新启动后(或当您重新启动时)完全恢复 感觉像这样)。无需配置。你应该感觉像你自己 永远不要放弃tmux。
py允许您在每个窗格中简单地列出所需的命令,并以包含三个破折号的行作为前缀。
下面是一个示例smux文件,它启动了三个窗格。
---
echo "This is pane 1."
---
cd /tmp
git clone https://github.com/hq6/smux
cd smux
less smux.py
---
man tmux
如果你把它放在一个叫做Sample的文件里。Smux,然后可以运行以下命令来启动。
pip3 install smux.py
smux.py Sample.smux
完全免责声明:我是smux.py的作者。
试试兄弟,这是一个项目引导器。
它提供了与tmux交互的简单api。
它看起来是这样的:
#!/bin/sh
# @ project_name/tasks/init.sh
structure project_name
window editor
run 'vim'
window terminal
run 'echo happy coding ...'
focus editor
connect project_name
要启动一个项目,所有人需要做的是运行以下命令-
兄弟开始<project_name>
检查下面的截屏,它展示了如何开始与兄弟和使用它的tmux api。
https://user-images.githubusercontent.com/8296449/50532502-2cf3e400-0b6e-11e9-84af-c5f77a04e5cc.gif
从我的“得到”。脚本,我每天早上都会调用它来运行一堆后续的“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