问题描述
如果某个应用不允许其他人开发插件,那么这个应用多半是个轻巧的小工具。如果允许其他人开发插件,那多半会发展成高级工具。tmux 想成高级工具以支持更多场景,因此它支持插件,这也是工具开发者在决定是否要允许他人开发插件的重要原因。
我们需要安装某些 tmux 插件,比如 Tmux Resurrect 用于保存 tmux 状态并恢复,还需要安装其他插件。
该笔记将记录:在 tmux 中,安装插件的方法,以及相关问题的处理。关于解决具体问题的插件,我们将记录在子章节。
解决方案
TPM – Tmux Plugin Manager
安装插件的方法有很多,插件的文档也会注明安装方法。我们这里将介绍使用 Tmux Plugin Manager 安装插件的方法,更多内容,参考 tmux-plugins/tpm: Tmux Plugin Manager 页面。。
第一步、安装 Tmux Plugin Manager 插件,并配置:
mkdir -pv ~/.config/tmux/ # Clone TPM: git clone https://github.com/tmux-plugins/tpm ~/.config/tmux/plugins/tpm # Put this at the bottom of ~/.tmux.conf ($XDG_CONFIG_HOME/tmux/tmux.conf works too) cat >> ~/.config/tmux/tmux.conf <<EOF # List of plugins set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' # Other examples: # set -g @plugin 'github_username/plugin_name' # set -g @plugin 'git@github.com:user/plugin' # set -g @plugin 'git@bitbucket.com:user/plugin' # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) run '~/.config/tmux/plugins/tpm/tpm' EOF # type this in terminal if tmux is already running tmux source ~/.config/tmux/tmux.conf
第二步、通过 TPM 安装插件(以 Tmux Resurrect 为例):
1)修改 ~/.config/tmux/tmux.conf 文件,添加 set -g @plugin "tmux-plugins/tmux-resurrect" 行,但是要在 run 命令之前;
2)执行 <prefix> + I 快捷键(虽然没有什么反应,但是 ps -ef | grep git 能够看到正在检出插件代码)
第三步、检查插件安装结束:
1)会显示 TMUX environment reloaded. Done, press ENTER to continue. 消息;
2)并且插件会在 ~/.config/tmux/plugins/ 目录中,这是我们目前(04/29/2021)已知检查插件安装是否成功的唯一方法。
注意事项
1)我们的对官方的安装文档进行简单修改,以将所有插件及配置保存在 ~/.config/tmux/ 目录中,以减少 ~/.* 文件的数量。
2)鉴于其他到 GitHub 拉取代码,则基本需要使用网络加速服务,参考 Use git over proxy 笔记。
tmux plugins(插件列表)
仓库 tmux-plugins/list: A list of tmux plugins. 记录着我们能用的 tmux 插件。
常见问题处理
Bash Completion(自动补全)
wget -P ~/.local/share/bash-completion/completions/ \ https://raw.githubusercontent.com/imomaliev/tmux-bash-completion/master/completions/tmux chmod u+x ~/.local/share/bash-completion/completions/tmux
相关链接
常见问题:tpm/tpm_not_working.md at master · tmux-plugins/tpm
自动安装 TPM 插件:tpm/automatic_tpm_installation.md at master · tmux-plugins/tpm
修改插件安装目录:tpm/changing_plugins_install_dir.md at master · tmux-plugins/tpm
如何编写插件:tpm/how_to_create_plugin.md at master · tmux-plugins/tpm
通过命令行对插件进行操作:tpm/managing_plugins_via_cmd_line.md at master · tmux-plugins/tpm
参考文献
Russell Parker | Bash Autocomplete for tmux
imomaliev/tmux-bash-completion: Tmux bash completion
tmux-plugins/list: A list of tmux plugins.
tmux-plugins/tpm: Tmux Plugin Manager