Fun with inputrc, part 1
If you’re using Linux or any other UNIX, the following should work just fine & dandy. If you use a Mac, you need to perform an extra step. Mac OS X doesn’t ship with any inputrc
file, either at /etc/inputrc
or ~/.inputrc
. First let’s create one, at ~/.inputrc
& then open it with your favorite text editor & add the following (or, open your text editor, add the following, & save it to ~/.inputrc
):
The first group is easy: use Unicode.
The second is a bit more complex, but is crazily useful. The history
command is a thing of beauty. Every command I type is saved, so I can always go back & see what I’ve typed or re-run a command.
If I press Ctrl-r
, I can search through my history, as you can see in the following, in which I show you what happens as I type each letter while I search my history for grep
:
Now if I press Enter1, that command runs: alias | grep hist
.
What if I want to find other commands in my history that used grep
? After I type out grep
& find one, just keep pressing Ctrl-r
to cycle back:
And so on.
If I’m just sitting at the prompt & type nothing & press the Up arrow, I go back through my command history one line at a time; if I press the down arrow, I go forward one line at a time. Press Enter, & the previous command runs. The problem is that this is often inefficient. Enter these two lines in ~/.inputrc
:
Now if I type a few letters of a command & press the Up arrow, the only commands that show up are those that contain the letters I just typed. Same thing for the down arrow. Like this (each of the following is on the same line, replacing the previous one; I’m just showing the commands on multiple lines so it’s obvious what’s happening):
And so on.
The third one means that I can use tab completion & not have to worry about capitalization. Normally, if this wasn’t enabled, I’d get this:
…aaaaand nothing except a beep. I’m telling bash
to cd
into a directory beginning with doc
, & there isn’t a directory that begins with doc
. There’s one that starts with Doc
, but that’s not matched.
If this line is in ~/.inputrc
, things will change:
And now I get:
Kinda hard to see in text like this, but as soon as I press Tab, doc
expands to Documents
. In other words, I can use tab completion without having to worry about capitalization, which is great for lazy people like me.
There’s more you can add in ~/.inputrc
, but those are a good start. Try them, get used to them, & then come back for more.
-
Yes, I could have stopped after typing
gr
, since the most recent command withgrep
in it was found. But I wanted you to see the whole thing. ↩