MLUG: [MLUG] tip of the week: Making good use of ~/.inputrc
[MLUG] tip of the week: Making good use of ~/.inputrc
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
I'm sure that you can learn a great deal about inputrc files from reading some of these web pages...

http://www.google.com/search?q=inputrc

...and these man pages:

man readline

...but I have one simple piece of advice: If you don't have one already, make a file called ~/.inputrc containing these two lines:

"\M-p": history-search-backward
"\M-n": history-search-forward

For me, this adds important functionality to bash and to Octave, and probably to some other programs.

From "man bash"

history-search-forward Search forward through the history for the string of characters between the start of the current line and the point. This is a non-incremental search. history-search-backward Search backward through the history for the string of characters between the start of the current line and the point. This is a non-incremental search.

Example. Suppose you want to recall a command from your bash command history and you remember that it began with 'perl.' You may have used perl in many pipes since then, so if you were to use Ctrl-r to search previous commands, and you were me, you would see all of these things that you didn't want to see...

less `which perlseq`
man perlpod
pod2man `which perlseq`
pod2man `which perlseq` > perlseq.1
man -M . perlseq.1
man -M . perlseq
mv perlseq.1 man/man1
man -M . perlseq
man -M ./man perlseq
pod2man `which perlseq` | man
pod2man `which perlseq` | man -
man -M ./man perlseq
less `which perlseq`
man -M ./man perlseq
man -M ./man perlseq
foreach sec ( `perlseq 1 1000` )
foreach sec ( `perlseq 1 1000` )
head -10 mult_combo.ped | perl -pe 's/^ +// ; s/ +/ /g ; s#/# #g' | less
head -20 mult_combo.ped | perl -pe 's/^ +// ; s/ +/ /g ; s#/# #g' | cut -d' ' -f 7 | less
head -12 mult_combo.ped | perl -pe 's/^ +// ; s#/# #g ; s/ +/ /g' | cut -d' ' -f -9 | numalign > merlin.ped
foreach N ( `perlseq 01 22` )

...and more that I have deleted! The trick is to type just the first few letters of the command and then hit Alt-P repeatedly. This will scroll through previous commands that began with those letters. If you go too fast and pass the one you were looking for, use Alt-N to scroll forward. This feature works in bash only if you have the ~/.inputrc described above. The same is true for newer versions of Octave and any other programs that use the readline library.

By the way, the term "\M-p" (meaning Meta-p) refers to the use of a "Meta key," but this key does not exist on most keyboards and Alt is used instead of Meta. If Alt doesn't work on some system, you can usually succeed with Esc p (Esc, ralease, then p).

Mike

--
Michael B. Miller, Ph.D.
Assistant Professor
Division of Epidemiology and Community Health
and Institute of Human Genetics
University of Minnesota
http://taxa.epi.umn.edu/~mbmiller/

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members