Create custom command in 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?


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.


bind C-p run "/usr/bin/notify-send Foo"


This is the full answer. You can have two tmux configuration. One contain

set status-left-length 0
set status-right-length 0
bind-key R source-file ~/.tmux.alternative.conf \; \
                    display-message "Alternative configuration loaded"

The other contain

set status-left-length 50
set status-right-length 15
bind-key R source-file ~/.tmux.conf \; \
                    display-message "Default configuration loaded"