⌘-k Hotkey in bash, on linux 29 Dec 2007
I never thought I would say “I wish my console acted more like the OSX’s Terminal.app”, but the truth is that I said that two days ago. That day my MacBook Pro (MBP) went out of commission due to an accidental overdose of Raspberry Iced Tea. Ever since then I’ve been plugging away on my Kubuntu box using Yakuake and Emacs23 to develop.

I have this obsessive need to clear the terminal all the time during development, primarily when I’m going to run tests. On my MBP I would just hit ⌘-k to clear the terminal, but I don’t have that luxury in Yakuake or any other terminal that I know of. So why not roll my own?

After googling around for a while I found this “article”:http://linuxgazette.net/issue55/henderson.html by Bryan Henderson from the “Linux Gazette”:http://linuxgazette.net . Even though the article is seven years old it still applies. In addition to this article I also read the man page for readline which has a lot of cool information in it. Since bash relies on readline to do the input processing new doors have opened for what I want to tinker with on my system.

Writing Your ⌘-k Hotkey

Create a ~/.inputrc file. In that file put the following contents. Now log out and log back in (or fire up a new terminal session):

"\C-x\C-r": re-read-init-file

The first line expresses that I want Meta-k to map to the following set of keystrokes:

  • C-a which brings me to the beginning of the line
  • C-k which cuts the line
  • clear which is used to clear the terminal
  • a newline which executes the clear command just as if I typed it and hit enter
  • C-y which pastes what I cut with C-k back onto the terminal

And now you have a Terminal.app ⌘-k hotkey on any system that uses bash. The only difference is that its mapped to Meta-k.

The second line is a simple nicety so you can reload your ~/.inputrc file without having to log out and log back in. Just type C-x C-r to reload any changes.

blog comments powered by Disqus