PDA

View Full Version : Bash: Incremental searching with Up and Down :)


ghostintheshell
July 15th, 2005, 09:13 PM
Yo, I found what I was searching for a long time \\:D/

What?

Incremental searching with Up and Down in a terminal

How?

- Open (or create) the .inputrc file in your home directory (~/.inputrc)
- Add these lines:

"\e[A": history-search-backward
"\e[B": history-search-forward

If that prevents Left and Right from working, fix them like this:

"\e[C": forward-char
"\e[D": backward-char

Close your terminal, re-open it and give it a try:
type ls foo
type foo
and now type ls followed by the up key --> it's magic \\:D/

And now enjoy your terminal :grin:

doclivingston
July 15th, 2005, 09:54 PM
You gotta love it when someone tell you something like this, and you say "why haven't I known about this for the past few years?".

Cheers.

ghostintheshell
July 15th, 2005, 10:31 PM
He he ... you should love this too:

Add these lines in your ~/.bashrc file:

#Make Bash correct small typos when moving to another directory
shopt -s cdspell

then restart your terminal and try:
cd /ec or cd /ur/locl

:-\"

Another one:

Add this line in your ~/.inputrc file:

set show-all-if-ambiguous on

now, restart your terminal and enjoy the real power of the <TAB> key ;)

professor_chaos
July 15th, 2005, 10:32 PM
why haven't I known about this for the past few years?

Thats very useful, thxs for posting.

doclivingston
July 15th, 2005, 10:47 PM
I already knew about "shopt -s cdspell", but it doesn't seem to do anything for me.

export HISTIGNORE="&:[bf]g:exit" is handy, it ignores bg, fg and exit when using the command history.

ghostintheshell
July 16th, 2005, 01:43 AM
Yo, another useful tip for the terminal killers we are :D

open ~/.bashrc
uncomment these lines:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi

=>

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

save, close. restart your terminal and try:
ls --c followeb by the <TAB> key
or
rm -- followeb by the <TAB> key

\\:D/

jaac
July 16th, 2005, 04:12 AM
Very nice tips :)

Anyone know how to have tab complete in a sftp session? that would be a great tip ;)

Caboto
July 16th, 2005, 04:57 AM
Some very cool tipps. Big thanks! I specially love the incremental searching thingie. :grin:

geearf
July 16th, 2005, 03:26 PM
Hello,

thanks for this how to, i can become very usefull.

But i still believe i won"t stay long with the first tweak, cause then if i wanna do somethink like nano .inputrc, then i realise i aint in the right directory, i need to go to the beginning of the line to get my old "cd".

Anyway, thanks

ghostintheshell
July 16th, 2005, 05:11 PM
Hello,

thanks for this how to, i can become very usefull.

But i still believe i won"t stay long with the first tweak, cause then if i wanna do somethink like nano .inputrc, then i realise i aint in the right directory, i need to go to the beginning of the line to get my old "cd".

Anyway, thanks

*** I don't understand the problem but if it is a 'key' problem you can configure it like you want!

"\e[A" = the up key
"\e[B" = the down key

but you can use, for example:

"\e[5~" = the page up key
"\C-n" = CTRL + 'n' key

more help on the web (google (http://www.justfuckinggoogleit.com/)) or simply here (http://www.linuxgazette.com/issue55/henderson.html)

*** You can also make different sections in your ~/.inputrc file for different applications:

for example:

$if mode=emacs
(...)
$endif

$if Bash
(...)
$endif

$if Ftp
(...)
$endif

more help on the web (google (http://www.justfuckinggoogleit.com/)) or simply here (http://www.linuxselfhelp.com/gnu/bash/html_chapter/bashref_8.html)

I don't test it but it is the idea ... Try it before give up ;)

Enjoy.

geearf
July 16th, 2005, 06:16 PM
Hello,

yes it was only a key problem, cause i like the way up and down work
you are right, i will try with other keys and it will be perfect thanks.

pgmario
July 18th, 2005, 06:43 PM
Thanks a lot! I was looking for this kind of completion ever since owning a Linux box and only using my ibook when I'm on the road. OS X has this behaviour enabled by default. Much more convenient than CTRL+R.

frodon
July 19th, 2005, 02:55 PM
Don't work at all for me !
It do absolutly nothing, why ? It doesn't work with tcsh terminal ?

EDIT : after some tests it seems that hotkey doesn't work with tcsh or the syntax should be different.