tmux 配置中的函数
Functions in tmux config
是否可以在 tmux config 中定义一个函数?对于给定的 tmux window,我有一个通用的工作流程,我想 运行。现在我已经在 bash 脚本中定义了它,该脚本获取 window 数字作为参数。示例:
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"
[...]
我有多个功能的这个设置。因此,除了我的 tmux.config
之外,我的 tmux 设置还需要多个 bash 脚本才能正常工作。我想把它弄平,最好把所有东西都放在 tmux.conf
中。有没有办法在我的 tmux 配置中定义函数并在其中使用 bash 命令?
据我所知,官方没有直接在.tmux.conf
中声明shell函数的方法。
如果您经常使用 bash
,那么在 default-command
中声明函数并使用 export -f
将它们公开给子进程可能会有所帮助,并使用 bash -i
.[=16 打开交互式屏幕=]
set-option -g default-command ' \
function switchWindow () { \
echo "Do something for "; \
}; \
function otherFunc () { \
echo "Do something for "; \
}; \
export -f switchWindow otherFunc; \
bash -i'
bind 1 send-keys "switchWindow 1" C-m
bind 2 send-keys "switchWindow 2" C-m
是否可以在 tmux config 中定义一个函数?对于给定的 tmux window,我有一个通用的工作流程,我想 运行。现在我已经在 bash 脚本中定义了它,该脚本获取 window 数字作为参数。示例:
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"
[...]
我有多个功能的这个设置。因此,除了我的 tmux.config
之外,我的 tmux 设置还需要多个 bash 脚本才能正常工作。我想把它弄平,最好把所有东西都放在 tmux.conf
中。有没有办法在我的 tmux 配置中定义函数并在其中使用 bash 命令?
据我所知,官方没有直接在.tmux.conf
中声明shell函数的方法。
如果您经常使用 bash
,那么在 default-command
中声明函数并使用 export -f
将它们公开给子进程可能会有所帮助,并使用 bash -i
.[=16 打开交互式屏幕=]
set-option -g default-command ' \
function switchWindow () { \
echo "Do something for "; \
}; \
function otherFunc () { \
echo "Do something for "; \
}; \
export -f switchWindow otherFunc; \
bash -i'
bind 1 send-keys "switchWindow 1" C-m
bind 2 send-keys "switchWindow 2" C-m