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):
"\ek":"\C-a\C-kclear\n\C-y"
"\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