Control, Oh!
So I’m brushing up on my shell-fu. In other words, working my way through the excellent and highly recommended From Bash to Z Shell, skimming the bits I know and experimenting with the bits I didn’t know. Here’s something I didn’t know; you may not either.
Ordinarily, a shell hint like this wouldn't make the bloggable threshold here on girtby.net, but I've been feeling a strong urge to blog again after an enforced absence, and this will do for now. Promise to return to regular nonsense service as soon as possible.
By default in bash and zsh the control-o key has some very useful behaviour. Let’s say you’re in a compile/edit/test cycle and you’re basically in a tight loop of shell commands. In this case you’re probably doing what I would have in the past, namely using up-arrow or control-r to manually locate the next command to execute from the history list.
% make ... % ./test ...
Try this at home (use “echo make” or similar). You quickly get bored of the double up-arrow to alternate between the two commands.
Control-o to the rescue!
Hit up-arrow twice to get back the to the make
command, but don’t hit return. Instead, hit control-o. This will execute the make command and leave you at the next in the history list — the ./test
command — ready to hit return again (or another control-o).
You can keep iterating through these two (or more!) commands with a single keystroke, each time previewing what you’re going to execute. I like it.
2 Comments