我如何设置tmux,使它启动与指定的窗口打开?
当前回答
试试兄弟,这是一个项目引导器。
它提供了与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交互的简单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
去https://github.com/remiprev/teamocil看看吧
你可以使用YAML指定你的结构
windows:
- name: sample-window
splits:
- cmd: vim
- cmd:
- ipython
width: 50
- cmd:
height: 25
创建新会话时,可以使用tmux钩子执行命令。具体来说,这是使用会话创建的钩子实现的。
例如,你可以在~/.tmux.conf文件中添加以下代码,将屏幕分成三部分,top在右下角运行:
set-hook -g session-created 'split -h ; split -v top'
这种方法的优点是,您不必以任何特殊的方式(即shell脚本或别名)运行tmux来获得所需的结果。您还可以将其与tmux new-session -A -s mysession结合使用,这样钩子命令只在您第一次创建会话时运行,而不是在后续的附件上运行。
该功能是由d15d54c2c在2016年添加的。包含它的第一个发行版是2.4。
你可以从.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)
我知道我的解决方案和其他人的很相似,但我找不到任何一个完全符合我的要求的解决方案:
我想在特定的路径上打开标题窗口 我想要尽可能多的窗户和玻璃 我想在每个窗格中运行任意命令,保存在历史记录中 我想要聚焦在脚本末尾的窗口 我希望能快速生成这个 我希望它易于维护
对于我名为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文件执行权限:-) 现在无论在哪里,我都要跑!