hook on pane closed

167 views
Skip to first unread message

Jakob Külzer

unread,
Aug 25, 2022, 1:20:49 AM8/25/22
to tmux-users
Hello friends,
I'm playing with tmux hooks for the first time and I can't seem to get the pane-died or pane-exited hook to work. I'm probably doing something wrong so I'd grateful for any pointers.

What I'm trying to do: execute a shell command (or just display-message) when the process in a pane exits.

What I've done so far (in tmux 3.3a):
$ tmux set-hook -p pane-focus-in 'display-message in'
$ tmux set-hook -p pane-focus-out 'display-message out'
$ tmux set-hook -p pane-exited 'display-message exited'
$ tmux show-hooks -p
pane-exited[0] display-message exited
pane-focus-in[0] display-message in
pane-focus-out[0] display-message out

So it looks like the hooks have been set up. However, none of them are executed, not when moving focus in or out or exiting the pane. Am I missing something here?

Cheers,
Jakob




Nicholas Marriott

unread,
Aug 25, 2022, 1:28:09 AM8/25/22
to Jakob Külzer, tmux-users
Do you have focus-events option on?

How are you exiting the pane? pane-exited will fire only when the process exits (not if you kill the pane) and only if remain-on-exit is off. I'm also not sure it will fire if the server itself exits, so not for the last pane in the server. 


--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/8a64cf58-8329-4080-aea2-2411c3ac39f9n%40googlegroups.com.

Jakob Külzer

unread,
Aug 25, 2022, 9:27:06 AM8/25/22
to Nicholas Marriott, tmux-users
Hi Nicholas,

Thanks for your response!

On 2022-08-25 01:27, Nicholas Marriott wrote:
> Do you have focus-events option on?

I did not have that on. Enabling it fixed the focus-in and focus-out hooks.

> How are you exiting the pane? pane-exited will fire only when the
> process exits (not if you kill the pane) and only if remain-on-exit is
> off. I'm also not sure it will fire if the server itself exits, so not
> for the last pane in the server.

The pane runs zsh; I exit via ^-D but I've tried `exit 1`. I didn't
realize remain-on-exit was required, the man page only specifies that
for pane-died.

Maybe I'm going about this wrong. I'm working on a text app and I'd like
it to spawn a new pane with an editor in it and then be notified once
the editor exits. Are hooks the right way to go about this?

Cheers,
Jakob

Nicholas Marriott

unread,
Aug 25, 2022, 9:34:16 AM8/25/22
to Jakob Külzer, tmux-users
remain-on-exit must be off for pane-exited. This definitely works for me (run and wait 1 second):

tmux -f/dev/null -Ltest new \; splitw \; set-hook -g pane-exited 'display foo' \; run -d1 \; send exit Enter

Hooks could work for this but it might be a bit clunky, there may be better alternatives. Do you want your process to block until the pane exits or just be signaled when it does?

Jakob Külzer

unread,
Aug 25, 2022, 4:34:32 PM8/25/22
to tmux-users
> remain-on-exit must be off for pane-exited. This definitely works for me (run and wait 1 second):
>
> tmux -f/dev/null -Ltest new \; splitw \; set-hook -g pane-exited 'display foo' \; run -d1 \; send exit Enter

Oh this does work, indeed. If I understand correctly this sets a global hook, so any pane in the session would trigger this event. Is there a way to apply a hook only to a specific split?

> Hooks could work for this but it might be a bit clunky, there may be better alternatives. Do you want your process to block until the pane exits or just be signaled when it does?

It certainly is starting to feel clunky. What I'm envisioning is the primary app to run in a pane. On command it will split off a new pane with an editor (e.g. vim) and continue to run so both can be used simultaneously. Once the editor exits, I'd like the primary app to react to that. Hooks seemed like the right way to go about that, but I'm not so sure anymore. I might have to do with mod times on the file or something like that.

Cheers,
Jakob

--
Cheers,
Jakob

Nicholas Marriott

unread,
Aug 25, 2022, 4:38:56 PM8/25/22
to Jakob Külzer, tmux-users
set-hook -p will set a hook on a pane but I'm not sure it will work when the pane is being destroyed, you may need to use a window or session hook and check hook_pane. 



--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages