hstr: history the easy way

The most common way of searching history is either history|grep ... or <Ctrl-r>. However, let’s face it, both of them are tedious and sometimes it’s really difficult to find that exact long and complex command you barely want to type in again. What if a tool could list all the matches visually and let you select the right command using search as you type? hstr is a new tool that does exactly the same thing. It’s a suggestion box or list of your command history with a lot of functionality built-in.

Features

  • View, navigate, select, search command history
  • Searches the list as you type and shows the matching results only
  • Add to favourite commands
  • Remove sensitive commands from history
  • Works for bash and zsh shells

Installation

To install hstr on Ubuntu, run:

$ sudo add-apt-repository ppa:ultradvorka/ppa
$ sudo apt-get update
$ sudo apt-get install hh

hstr has minimal dependencies. If you want to compile it from the latest source on Ubuntu, run:

$ sudo apt-get install libncursesw5-dev libreadline6-dev
$ git clone https://github.com/dvorka/hstr.git
$ cd hstr/
$ cd ./dist && ./1-dist.sh && cd ..
$ ./configure && make
$ sudo make install

Usage

  • Optionally add config to ~/.bashrc
    $ hh --show-configuration >> ~/.bashrc
  • List history (hh is the command for hstr)
    $ hh

    Once you get the list, keep typing for the exact match.

  • List history with all matches for “virt”
    $ hh virt
  • Get more help
    $ man hh

Keys

Ctrl-e : Toggle regular expression and substring search.
Ctrl-t : Toggle case sensitive search.
Ctrl-/ : Rotate view of history as provided by BASH, ranked history ordered by the number of occurences/length/timestamp and favorites.
Ctrl-f : Add currently selected command to favorites.
Ctrl-l : Make search pattern lowercase or uppercase.
Ctrl-r, UP arrow, DOWN arrow, Ctrl-n, Ctrl-p : Navigate in the history list.
TAB, RIGHT arrow : Choose currently selected item for completion and let user to edit it on the command prompt.
LEFT arrow : Choose currently selected item for completion and let user to edit it editor (fix command).
ENTER : Choose currently selected item for completion and execute it.
DEL : Remove currently selected item from the shell history.
BACSKSPACE, Ctrl-h : Delete last pattern character.
Ctrl-u, Ctrl-w : Delete pattern and search again.
Ctrl-x : Write changes to shell history and exit.
Ctrl-g : Exit with empty prompt.

On GitHub: hstr

Similar software

  • fzf: Fuzzy finder for your shell

One thought on “hstr: history the easy way”

Leave a Reply

Your email address will not be published. Required fields are marked *