statik / hui

A visual alternative to the history command written in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hui - A visual alternative to history written in Rust

Demo of hui

Overview

hui is command-line tool to quickly search through your terminal history. The motivation behind this tool was having a prettier and faster way to do history | grep <search>. I would do this frequently to remember some docker or curl command I had done recently, but couldn't remember the flags I used. This now lets me search through my history and copy the command I want a lot easier.

hui is built on top of ratatui for its TUI, or Terminal User Interface.

Setup

Installation

If you are on a Mac, you can install from homebrew:

brew tap jmwoliver/hui
brew install hui

Alternatively, you would like to install from source if you have cargo installed locally:

git clone https://github.com/jmwoliver/hui.git
cd hui
cargo build --release
# you can then alias the command so it is available in any directory:
# alias hui=<CURRENT_DIR>/target/release/hui

Configuration

After installing hui, it will need to know which shell you are using. This can be done by setting the HUI_TERM environment variable.

For zsh, run the following commands:

echo 'export HUI_TERM="zsh"' >> ~/.zshrc
source ~/.zshrc

If you are using bash, run:

echo 'export HUI_TERM="bash"' >> ~/.bashrc
source ~/.bashrc

Bash doesn't automatically write the history back to the .bash_history file like ZSH does. The following can be added to your .bashrc file to append the history for each command (based on a StackExchange response):

unset HISTFILESIZE
HISTSIZE=3000
PROMPT_COMMAND="history -a"
export HISTSIZE PROMPT_COMMAND

shopt -s histappend

Then remember to:

source ~/.bashrc

Usage

Once everything is installed and the HUI_TERM environment variable is set, all you have to do to run it is:

hui

Now you can scroll through all your history, filter results, and select a command to copy to your clipboard.

Enjoy!

Acknowledgements

I used several projects for inspiration or guidance:

  • ratatui: Incredible TUI framework and useful examples
  • hstr-rs: Helped me better understand how to ingest and parse the .zsh_history file
  • hoard: Similar concept to hui and I liked how they had the searchbar at the bottom

About

A visual alternative to the history command written in Rust


Languages

Language:Rust 100.0%