Last active
November 25, 2019 17:28
-
-
Save songlairui/ed6476404de3ce76953b3e9144876933 to your computer and use it in GitHub Desktop.
Tmux open with multi-pane within different working dir. 使用tmux快速切换到多个工作目录。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 使用 nodejs 打开 | |
*/ | |
const { spawnSync } = require("child_process"); | |
// 关闭 tmux-session | |
spawnSync("tmux", ["kill-session", "-t", "developing"]); | |
// 打开上方 `open-tmux.sh` | |
spawnSync("osascript", [ | |
"-e", | |
'tell application "Terminal" to do script "/Users/songlairui/space/songlairui-repo/tmux/open-tmux.sh"' | |
]); | |
// 展开上方 open-tmux.sh 内容 | |
const innerCommand = `tmux new -s developing \\\\; \ | |
send-keys '/Users/songlairui/space/songlairui-repo/developing' C-m \\\\; \ | |
send-keys 'clear' C-m \\\\; \ | |
split-window -v \\\\; \ | |
send-keys '/Users/songlairui/space/songlairui-repo/developing-web' C-m \\\\; \ | |
send-keys 'clear' C-m \\\\;`; | |
spawnSync("osascript", [ | |
"-e", | |
`tell application "Terminal" to do script "${innerCommand}"` | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
tmux new -s developing \; \ | |
send-keys '/Users/songlairui/space/songlairui-repo/developing' C-m \; \ | |
send-keys 'clear' C-m \; \ | |
split-window -v \; \ | |
send-keys '/Users/songlairui/space/songlairui-repo/developing-web' C-m \; \ | |
send-keys 'clear' C-m \; | |
# osascript -e 'tell application "Terminal" to do script "/Users/songlairui/space/songlairui-repo/tmux/open.sh"' |
TODO
- 默认执行命令, 如
yarn serve
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
open-tmux.sh
中的反斜杠为两种反斜杠:open-tmux.js
中,确保spaw 标准输入接收到的字符串为\\
, 声明字符串就需要为\\\\
, 试验得出。