Arnold Roa
Arnold Roa

Reputation: 7748

Single easier command to search in bash history

On of the commands that I wrote the most on daily basis on my console is

# history | grep -i 'something'

That and ctr+r is probably what I use the most :).

I was thinking in have something like

# h something

Or even better, a live search like ctr+r but that shows all results at glance, not only one. I know i can cycle pressing ctrl+r again, but would be better if I could see what are all the elements that I"m cycling.

So this is 2 questions:

1) Do you know any program that provide a better interface for bash history in console?

2) What is the best way to accomplish my h something alias?

Upvotes: 6

Views: 449

Answers (4)

Martin Dvorak
Martin Dvorak

Reputation: 812

Perhaps you may want to try https://github.com/dvorka/hstr which is "suggest box style" filtering of Bash history - you get hh 'something' - for instance hh an:

enter image description here

It can be easily bound to Ctrl-r and/or Ctrl-s

Upvotes: 1

Michael Ballent
Michael Ballent

Reputation: 1088

In my .bash_profile is set the following in there:

set -o vi

then I have the functionality of vi from the command line

Hitting the ESCape key followed by k will return the last line entered

ESC-k

keep hitting k so that it scrolls up. The magic happens when you then hit the slash key (/). Then you can search your history

http://www.thegeekstuff.com/2009/10/do-you-like-to-perform-vi-style-editing-in-bash-command-line/

Upvotes: 0

jherran
jherran

Reputation: 3367

Want a h command. Easy, add an alias in your .bashrc or .bash_profile or .bash_aliases (depending on your config).

alias h="history | grep -i"

Upvotes: 2

Arnold Roa
Arnold Roa

Reputation: 7748

One way to acomplish the h something is adding to .bash_profile:

 alias h="history | grep -i "

I'm actually using zsh but i guess it will work too

Upvotes: 0

Related Questions