Skip to content

Instantly share code, notes, and snippets.

@ThomasAdam
Created November 3, 2012 11:36
Show Gist options
  • Save ThomasAdam/4007114 to your computer and use it in GitHub Desktop.
Save ThomasAdam/4007114 to your computer and use it in GitHub Desktop.
set-hook example for .tmux.conf
set-hook -g -n 'before-new-session' 'run "notify-send new-session..."'
set-hook -g -n 'after-new-window' 'run "notify-send new-window..."'
new -sfoo
set-hook -tfoo -n 'after-split-window' 'display-message "I split this window!"'
set-hook -tfoo -n 'before-new-window' 'splitw ; run "notify-send YES"'
neww -d
neww -d
@kaushalmodi
Copy link

Hi, I ended up here via googling. I was curious if after-new-window hook existed, and I found your example using it. But it doesn't seem to be documented in this list: http://man7.org/linux/man-pages/man1/tmux.1.html#HOOKS

Also it doesn't mention the use of "before-" prefix.

@tony
Copy link

tony commented Nov 26, 2017

@kaushalmodi

The manual's list of hooks, as of 2.6, are only the specialty hooks. I had to re-read it a few times. The command hooks themselves aren't listed one-by-one.

tmux allows commands to run on various triggers, called hooks. Most
tmux commands have an after hook
and there are a number of hooks not
associated with commands.

A command's after hook is run after it completes, except when the com‐
mand is run as part of a hook itself. They are named with an ‘after-’
prefix...

So if there is a command, there is (most of the time) an after- hook for it.

Here is after-new-window in the source code: https://github.com/tmux/tmux/blob/2.6/cmd-new-window.c#L150

Search the code for hook triggers: https://github.com/tmux/tmux/search?utf8=%E2%9C%93&q=hooks_insert%28&type=

Another place where hooks are added: https://github.com/tmux/tmux/blob/2.6/cmd-queue.c#L248 in cmdq_fire_command()

I also wrote an article about tmux hooks at https://devel.tech/tips/n/tMuXz2lj/the-power-of-tmux-hooks/ where i give some usage examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment