tmux

Is it possible to add custom commands to tmux?


I have some commands in mind that I don't want to create keybinds for and would prefer to use command mode for them. For example, I want something like:

<C-a>:restart-guard

That I can have run a script to run some commands in my guard window

Is this possible?


Solution

  • You can't define user defined commands directly But you can always call a tmux script with so (shortest alias of source-file) or a program with ru (shortest alias of run-shell)

    For so, you need to give the path to the command or to have the tmux server to start in the folder where your custom commands are

    Here is a simple example, you put your restart-guard script in ~/.tmux/commands you start tmux using a scipt :

    #!/bin/bash
    cd ~/.tmux/commands
    tmux
    

    then inside tmux, do

    <C-a>:so restart-guard
    

    I am currently looking for a way to have the directory where you started tmux and not the ~/.tmux/commands directory when starting