I don't think my tmux does support multiline quotes :( however i have it
working with this:
set -g remain-on-exit on
set-hook -g pane-died {
if -F "#{&&:#{==:#{window_name},netkit-vm},#{==:#{pane_index},0}}" {
run-shell "tmux -L netkit has-session -t '=#{session_name}-dead' &&
tmux kill-session -t '=#{session_name}-dead'; tmux -L netkit rename-session
-t '=#{session_name}' '#{session_name}-dead'"
} {
run-shell "tmux -L netkit kill-pane -t
#{session_name}:#{window_name}.#{pane_index}"
}
}
Thanks for your help!!
On Wednesday, 6 January 2021 at 17:18:07 UTC [email protected] wrote:
> if-shell does not expand formats in its command arguments for some reason.
>
> Also this will not work if the old session does not exist, because the
> kill-session will fail so the rename-session will not run.
>
> You need to wrap it in run-shell which does expand formats, and run them
> as separate commands:
>
> set -g remain-on-exit on
> set-hook -g pane-died {
> if -F "#{&&:#{==:#{window_name},netkit-vm},#{==:#{pane_index},0}}" {
> run-shell "
> tmux kill-session -t '=#{session_name}-dead'
> tmux rename-session -t '=#{session_name}'
> '#{session_name}-dead'
> "
> }
> }
>
> If your tmux is too old for multiline "s, then you will have to do "tmux
> kill-session ...; tmux rename-session ...".
>
> If you are using a tmux which is older and does not support {}, quoting
> will be quite annoying. Personally I would probably put the whole hook in a
> shell script and just pass in #{session_name} #{window_name} and
> #{pane_index} as arguments:
>
> set-hook -g pane-died 'run-shell "/path/to/my/script \"#{q:session_name}\"
> \"#{q:window_name}\" #{pane_index}"'
>
> Then you can do whatever you like in the script (but be careful of races
> with multiple separate tmux commands).
>
>
> On Wed, 6 Jan 2021 at 16:43, Billy Bromell <[email protected]> wrote:
>
>> Hi,
>>
>> I think I've got the wrong syntax for this, any pointers would be
>> appreciated!
>>
>> ```
>> # If pane 0 dies, kill any previous MACHINE-dead sessions, and rename
>> this session
>> # from MACHINE to MACHINE-dead
>> set-hook -g pane-died 'if -F
>> "#{&&:#{==:#{window_name},netkit-vm},#{==:#{pane_index},0}}" "kill-session
>> -t #{session_name}-dead; rename-session #{session_name}-dead" "kill-pane"'
>> ```
>>
>> I'm trying to make it so that if the process in window netkit-vm, pane 0
>> dies, then the session gets renamed to append '-dead' to the current name
>> (session a > session a-dead), however it needs to kill the -dead sessions
>> of the same name before, otherwise rename-session would fail as it would be
>> a duplicate session.
>>
>> The if statement seems to be working fine but kill session is failing (i
>> get a message in the status bar showing the correct usage of kill-session).
>> Are there some escape characters I'm missing for the variables?
>>
>> Thanks,
>> Billy
>>
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web, visit
>> https://groups.google.com/d/msgid/tmux-users/7dace6e6-2355-424c-bfd4-98e8b4ba15c9n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/tmux-users/7dace6e6-2355-424c-bfd4-98e8b4ba15c9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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 [email protected].
To view this discussion on the web, visit
https://groups.google.com/d/msgid/tmux-users/6dd1d79e-9fa9-48f5-ad83-36728a8670a1n%40googlegroups.com.