Is it possible to define a function in tmux config? I have a generic workflow that I want to run for a given tmux window. Right now I have defined this in a bash script which gets the window number as a parameter. Example:
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"
[...]
I have this setup for multiple functions. So, besides my tmux.config
, multiple bash scripts are required for my tmux setup to work. I want to flatten this out and ideally have everything in the tmux.conf
. Is there a way to define functions in my tmux config and use bash commands inside them?
As far as I know, there is no official way to declare shell function directly in .tmux.conf
.
If you use bash
usually, it might be helpful to declare functions in default-command
and expose them to child processes with export -f
, and open interactive screen with 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With