screen 的一个很好的功能是它能够将键盘快捷键分配给称为“类”的组。使用bind -c
,您可以将该快捷方式分配给特定类,并且绑定command -c <class>
到一个键允许您选择该类。这允许多层键盘快捷键。例如,我用x
键来选择一个类专用的常用命令。通过在它们自己的类中拥有这些启动器快捷方式,可以使用助记键而不必担心与正常的键绑定集冲突。有什么办法可以复制这个功能tmux
吗?
# from my .screenrc
bind -c execute o screen -t imap 10 offlineimap.sh -o
bind -c execute m screen -t mpd ncmpcpp
bind -c execute w screen -t vw vimwiki
# ... more application launchers
bind x command -c execute
Run Code Online (Sandbox Code Playgroud)
用法:prefixx进入启动器键类,我将所有应用程序键盘快捷键都放在这里。
在更好地理解您要做什么之后,我认为一个简短的 bash 脚本是最好的方法(抱歉,我认为不存在tmux
类似于screen
命令类的-only 解决方案):
在.tmux.conf
:
bind-key x command-prompt -p "launch what?" " "run-shell \"tmux-launcher %%\""
Run Code Online (Sandbox Code Playgroud)
tmux-launcher
应该是路径中某处的可执行 shell 脚本:
#!/bin/bash
case $1 in
o) tmux new-window -n imap -t 10 offlineimap.sh -o ;;
m) tmux new-window -n mod ncmpcpp ;;
w) tmux new-window -n vw vimwiki ;;
esac
Run Code Online (Sandbox Code Playgroud)
一个缺点是您必须在选择要创建的窗口的字母后键入 return。