2009-09-19

fix the M-. behavior in iTerm under Snow Leopard

I found that one of my favorite keyboard shortcuts refused to work, after my MB has been upgraded to the Snow Leopard. That striking keybinding is "M-.", which used to bring the last argument of the most recently committed bash command to the cursor's very position on bash's input line(thanks to libreadline, which provides this feature and other which are similar to those keybinding in Emacs[God's editor, yes]), now will introduce a "≥" symbol instead in iTerm.

iTerm is more user-friendly than the Terminal.app which is originally contained in Leopard and Snow Leopard. For example I can use Command+1, Command+2 to switch to different tabs in iTerm(and I know that GNU Screen can sometimes make the tabs useless and unnecessary, but consider that what if I'm connected to several remote hosts via ssh?), which may not be possible(or at least not easy to do so) in Terminal.app. And that's why I feel that life sucks when forced to use the Terminal.

I had thought that it's because the iTerm is too old to work with SL, because that version was released in April, 2009 and it indeed worked smoothly in Leopard. So I decided to wait for a newer version of iTerm. And today when the newer version comes. I can't help to upgrade it, with full expectation that it will solve that problem(M-. does not work as it did). But, I was made disappointed because, it DOES NOT work like that!

OK. Maybe I have to turn to some other dirty way. I first tried to use the mapping function in iTerm to deceive bash that whenever the M-. is pressed it should be taken as the right keycode to bring up the last argument of the last bash command. but I failed because, the "xev" program reported the same keycodes in both iTerm and Terminal(remember that M-. works as _I_ expected in Terminal).

Then, I remembered that I had once made some customized keybindings in bash via the ~/.inputrc file under Linux, which controls mappings between keyboard inputs and what bash see. With even no expectation that it will work, I put this line:

"≥": yank-last-arg
into my ~/.inputrc.

After iTerm's relaunch, M-. succeeds to just emit the last argument... which I have longed for about 4 weeks.