Fun With Readline
Every now and then I dig up a
bash tutorial
and learn a few new tricks. The fc built-in caught my eye this time. fc allows you to edit the last command in a traditional text editor. When you quit the editor, the contents of the buffer are evaluated by the shell.
fc is really useful for debugging long pipelines or long ruby operations performed from the command line. The default editor can be customized by changing the FCEDIT variable. I tried making vim the default, but with all my plugins, it loads too slowly. I ended up doing the following:
export FCEDIT="vim --noplugin"
I also figured out how to yank back in deleted strings. You can insert the most recently deleted string by hitting C-y. I learned a couple of neat history tricks as well. If you type !* in a command line sequence, it will replace it with all but the first word of the last command entered. !$ will be replaced with just the last word of the last command, making it the equivelent of the C-. shortcut.
While I was poking through the documentation, I took the time to learn the readline config file format. I configured M-h to perform the history-search-backward operation, which is like cycling back through the history, but only using lines that start the same way the current line does. Check out some of the other spiffy readline commands you can bind to shortcuts.
Posted on 2005-04-040 comments
