我如何设置tmux,使它启动与指定的窗口打开?
当前回答
我知道我的解决方案和其他人的很相似,但我找不到任何一个完全符合我的要求的解决方案:
我想在特定的路径上打开标题窗口 我想要尽可能多的窗户和玻璃 我想在每个窗格中运行任意命令,保存在历史记录中 我想要聚焦在脚本末尾的窗口 我希望能快速生成这个 我希望它易于维护
对于我名为johndoe的项目,我创建了一个johndoe.conf文件,它本质上是一个bash脚本,在我的配置(~/.config/tmux/tmux-sessions/johndoe.conf)的某处。
这个文件很容易维护,因为它不像我在其他答案中看到的那样有无数的\ everywhere:
# Create a new session named johndoe, with a first window named Main
# at the specified starting path.
# The -d is for detached mode, which allows me to continue defining the rest of the session
# before attaching to it. Without -d, tmux would open the client right away and
# ignore the rest of the session definition
tmux new -d -s johndoe -n 'Main' -c ~/dev/own/johndoe
# Simulate the user entering some docker command in the first window available
# in the target session named (-t) johndoe
tmux send -t johndoe 'docker compose up -d' Enter
# Create a new window in the target session, with the title 'UI run'
tmux neww -t pers -n 'UI run' -c ~/dev/own/johndoe/front-end
# Simulate user entering a command to the first pane
tmux send -t pers:'UI run.0' 'git status --short' Enter
# Split this window horizontally
tmux split-window -t pers:'UI run' -h -c ~/dev/own/johndoe/front-end
# Simulate user entering a command to the second pane in this window
tmux send -t pers:'UI run.1' 'npm run dev' Enter
tmux neww -t johndoe -n 'API run' -c ~/dev/own/johndoe/back-end/Api
tmux send -t johndoe:'API run' 'dotnet run --no-build' Enter
# Focus the first window
tmux select-window -t johndoe:'Main'
# Attach the current terminal to the only session available
# (you might want to add "-t johndoe" here if you need several sessions running in parallel)
tmux a -d
我创建了一个bash/zsh别名来源会话配置:
alias tmuxjohndoe='. ~/.config/tmux/tmux-sessions/johndoe.conf'
我花了适量的调试时间,弄清楚我需要给johndo .conf文件执行权限:-) 现在无论在哪里,我都要跑!
其他回答
这对我很有用。创建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
我知道我的解决方案和其他人的很相似,但我找不到任何一个完全符合我的要求的解决方案:
我想在特定的路径上打开标题窗口 我想要尽可能多的窗户和玻璃 我想在每个窗格中运行任意命令,保存在历史记录中 我想要聚焦在脚本末尾的窗口 我希望能快速生成这个 我希望它易于维护
对于我名为johndoe的项目,我创建了一个johndoe.conf文件,它本质上是一个bash脚本,在我的配置(~/.config/tmux/tmux-sessions/johndoe.conf)的某处。
这个文件很容易维护,因为它不像我在其他答案中看到的那样有无数的\ everywhere:
# Create a new session named johndoe, with a first window named Main
# at the specified starting path.
# The -d is for detached mode, which allows me to continue defining the rest of the session
# before attaching to it. Without -d, tmux would open the client right away and
# ignore the rest of the session definition
tmux new -d -s johndoe -n 'Main' -c ~/dev/own/johndoe
# Simulate the user entering some docker command in the first window available
# in the target session named (-t) johndoe
tmux send -t johndoe 'docker compose up -d' Enter
# Create a new window in the target session, with the title 'UI run'
tmux neww -t pers -n 'UI run' -c ~/dev/own/johndoe/front-end
# Simulate user entering a command to the first pane
tmux send -t pers:'UI run.0' 'git status --short' Enter
# Split this window horizontally
tmux split-window -t pers:'UI run' -h -c ~/dev/own/johndoe/front-end
# Simulate user entering a command to the second pane in this window
tmux send -t pers:'UI run.1' 'npm run dev' Enter
tmux neww -t johndoe -n 'API run' -c ~/dev/own/johndoe/back-end/Api
tmux send -t johndoe:'API run' 'dotnet run --no-build' Enter
# Focus the first window
tmux select-window -t johndoe:'Main'
# Attach the current terminal to the only session available
# (you might want to add "-t johndoe" here if you need several sessions running in parallel)
tmux a -d
我创建了一个bash/zsh别名来源会话配置:
alias tmuxjohndoe='. ~/.config/tmux/tmux-sessions/johndoe.conf'
我花了适量的调试时间,弄清楚我需要给johndo .conf文件执行权限:-) 现在无论在哪里,我都要跑!
试试兄弟,这是一个项目引导器。
它提供了与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
有一个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启动时自动恢复