tmux 配置中的功能

fwi*_*ind 4 bash tmux

是否可以在 tmux 配置中定义一个函数?我有一个通用工作流,我想为给定的 tmux 窗口运行它。现在我已经在 bash 脚本中定义了它,该脚本将窗口编号作为参数。例子:

bind 1 run-shell "~/.config/tmux/switchWindow.sh 1"
bind 2 run-shell "~/.config/tmux/switchWindow.sh 2"
bind 3 run-shell "~/.config/tmux/switchWindow.sh 3"
bind 4 run-shell "~/.config/tmux/switchWindow.sh 4"
[...]
Run Code Online (Sandbox Code Playgroud)

我有多种功能的设置。因此,除了我的tmux.config.bash 脚本之外,我的 tmux 设置还需要多个 bash 脚本才能工作。我想把它弄平,最好把所有东西都放在tmux.conf. 有没有办法在我的 tmux 配置中定义函数并在其中使用 bash 命令?

小智 7

据我所知,没有官方的方法可以直接在.tmux.conf. 如果您bash经常使用,在 中声明函数default-command并使用 将它们公开给子进程可能会有所帮助export -f,并使用 来打开交互式屏幕bash -i

set-option -g default-command '   \
function switchWindow () {        \
  echo "Do something for $1";     \
};                                \
function otherFunc () {           \
  echo "Do something for $1";     \
};                                \
export -f switchWindow otherFunc; \
bash -i'

bind 1 send-keys "switchWindow 1" C-m
bind 2 send-keys "switchWindow 2" C-m
Run Code Online (Sandbox Code Playgroud)