1

I am trying to get hollywood to run in a way that I can exit it with a normal Ctrl+C signal. Currently I have to press Ctrl+C a bunch of times just to get stuck in the tmux instance that hollywoodcreated. Looking at the source code, there is a trap command:

trap "pkill -f -9 lib/hollywood/ >/dev/null 2>&1; exit 0" INT

But apparently that is not enough. I've tried replacing it with several different ones, but none of them was able to do it right:

trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

trap 'kill $(jobs -p)' EXIT

trap 'pkill -f -9 lib/hollywood/ >/dev/null 2>&1; kill -9 $(ps -eo pid,command | grep tmux | grep byobu | grep hollywood | sed -r "s/^[^0-9]*([0-9]+).*/\1/") >/dev/null 2>&1; exit 0' INT

trap "exit" INT TERM
trap "kill 0" EXIT

I've tried several answers of this question: How do I kill background processes / jobs when my shell script exits? But none of those worked. (I still had to press Ctrl+C a bunch of times and then manually exit the tmux session.)

Is there a simple way to fix this? (I would prefer to having to mess with the source code too much.)

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Forivin
  • 14,780
  • 27
  • 106
  • 199

1 Answers1

1

They aren't background processes, they are running in different tmux panes - tmux is the parent process, not the hollywood script. So most of the commands you list won't have any effect.

pkill should work if the pattern is right. Does the pkill work if you run it from outside tmux? It looks like each hollywood widget installs its own trap with the same pkill so it should kill them all if any one is killed.

Alternatively, if you are not running it in your own tmux server, you could simply make C-c kill the tmux window - change hollywood to do something like this when it creates the tmux session (around line 78):

$tmux_launcher bind -n C-c kill-window

If you have an existing tmux that you don't want to kill, this is harder because you want C-c for other purposes. You could change your C-c binding to something like:

bind -n C-c if -F '#{==:#{window_name},hollywood}' 'kill-window' 'send C-c'

But you might not want to do this unless you are using hollywood a lot.

It might be more useful to ask this in the hollywood issue tracker than here TBH.

Nicholas Marriott
  • 3,148
  • 9
  • 12
  • Thank you, the first C-c binding works, but it will kill all hollywood instances... So I tried the second one, but that one (not sure why) didn't work at all. I inserted the `$tmux_launcher bind ...` line right below the `$tmux_session new-session ...` line in case that matters. ... About my pkill, yes it did work when running it manually from another terminal. – Forivin Dec 10 '19 at 21:09
  • Hmm if the pkill works outside then the trap should work, if it doesn't I would suggest reporting it to the developers. I don't know why ^C doesn't work, which one are you having trouble with? The if -F one? – Nicholas Marriott Dec 10 '19 at 21:44
  • Note pkill will kill all hollywood instances of course. – Nicholas Marriott Dec 10 '19 at 21:48