Create custom command in tmux

tmux

I know how to bind a key to a command in tmux, but I want to create a custom command (that you can type with prefix key + colon). In this custom command, I want to execute a couple of other commands.

My idea is to have something like this:

no-side-status() {
    set status-left-length 0
    set status-right-length 0
}

side-status() {
    set status-left-length 50
    set status-right-length 150
}

So I can type :no-side-status to hide the left and right status bars, and type :side-status to restore the left and right status bars.

Is it possible to create such custom commands? If so how? If not, any other way to achieve what I want?

Best Answer

Originally, tmux doesn't have any support for custom commands except for running external shell scripts.

There's a mod adding full-fledged scripting support to tmux: http://ershov.github.io/tmux/

It also allows to create user commands. For example, yours would look like:

proc no-side-status {} {
    set status-left-length 0
    set status-right-length 0
}

proc side-status {} {
    set status-left-length 50
    set status-right-length 150
}

To use from tmux command line just type C-b : and side-status or no-side-status.

To bind it to a key use bind C-p tcl side-status.

Related Question