Thoughts on Perl and Emacs, technology and writing

Executing the Same Command on Multiple Shell Buffers

Is there an easy way to select (via buffer-name regex or similar) a subset of terminals in elisp, and then squirt the same command into each one?

Sure Gaz, that sounds fairly straightforward. The shell wrappers already stores the terminal buffers in sw-buffers. We just need to think of how we want to select the buffers. And it probably doesn’t come as any surprise that I’m going to use ido.

Ido provides regex matching by pressing C-t or defining ido-enable-regexp. It also has flex matching with ido-enable-flex-matching and you can continuously refine selections using C-SPC. It really is amazingly cool.

Surprisingly, I couldn’t find a straightforward way of accessing the interim matches. Nor is there a hook that executes at selection time. Instead, we will override RETURN. Dynamic scoping means we can define an effectively global variable, sw-buffer-matches to store the interim matches for later use. Then, we iterate over these matches and send the command using term-simple-send.

We only want RETURN to be overridden for this particular usage of ido, so we set the keymap on the ido-setup-hook.

I’ve been using your sw-multi-cmd code for a couple of hours now, and it works better than screen for sending a command to all the open sw-buffers.

However, I’m not sure that ido is the right tool for narrowing the buffer list interactively. It makes it difficult to choose ‘these 20 machines from my list of 30’, or ‘all machines except this one, this one and this one’. Actually, as long as I’ve memorized the names and architectures of all 30 of the machines I’m working with, I can use the regex matching mode… but is there a nicer way to do it?

Gaz

I remembered to tick ‘Notify me of follow-ups by email’ this time, so it won’t take me 8 months to find my way back this time 🙂