Live data from Hacker News

$!134 can be a nice bash foot shooter if you accidentally mistype the number

news.ycombinator.com

51–54 of 54 posts

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#51
post #49
post #5

Earlier quoted context omitted.

I always add "\e[A": history-search-backward "\e[B": history-search-forward to my .inputrc, I find it easier to use than C-r as it's some sort of autocomplete from history. But looking up commands with !number can still be very useful when you don't remember the command you need but remember when you used it (e.g. what commands you ran before and after).

What are the "\e[A" and "\e[B" do, are they key presses? I usually do `history | grep ...` to find the command and then use it. Non-emacs users might tend to find this surprising, but in a shell buffer you can move around with your cursor like in a text file, so after executing `history` you can search for the command as string then copy-paste it.

Yep, it binds history search to key up and key down. Start typing a command, press up or down and it will scroll through matching completions from history

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#53

keep calm and `shopt -s histverify` on

Hey that's super cool, thanks! Works great!

For those who want to read about shopt, check:

http://www.gnu.org/software/bash/manual/bash.html#The-Shopt-...

Took me a bit to find it, and there seems to be no man entry.

Most important commands:

shopt -s histverify # activates the option

shopt -u histverify # deactivates the option

shopt # shows all available options and their activation status

You must put "shopt -s histverify" to your .bashrc so that it stays activated.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#54
Never had an issue with this. Change your shell prompt to include the history line number. Remember, it's session dependent - if you have two simultaneous shells, the command number can be the same across both of them (so don't expect it to always work across different terminal sessions).
Post reply on HN