hun

Crates.iohun
lib.rshun
version0.1.0
created_at2025-12-23 00:11:13.740292+00
updated_at2025-12-23 00:11:13.740292+00
descriptionHun: The History Unification Node. A supercharged shell history tool with SQLite backend and TUI.
homepagehttps://github.com/dotandev/hun
repositoryhttps://github.com/dotandev/hun
max_upload_size
id2000500
size57,594
dotdev. (dotandev)

documentation

https://docs.rs/savert/hun

README

Hun: The History Unification Node 🏹

Hun is a supercharged shell history tool written in Rust. It replaces your standard shell history with a SQLite-backed database, offering better persistence, metadata tracking (exit codes, execution time, directory), and a powerful TUI for fuzzy searching.

Hun TUI

Features

  • SQLite Backend: Your history is stored in a robust SQL database, not a fragile text file.
  • Rich Metadata: Tracks Exit Code (✅/❌), Timestamp, Current Working Directory, and Session ID.
  • Interactive TUI: Built with ratatui, offering instant fuzzy search.
  • Shell Integration: Seamless hooks for Zsh and Bash.
  • Stats: View your most frequently used commands with hun stats.

Installation

From Crates.io

cargo install hun

From Source

git clone https://github.com/dotandev/hun.git
cd hun
cargo install --path .

Setup

To start recording commands, you need to hook hun into your shell.

Zsh

Add the following to your ~/.zshrc:

# Hun Integration
function hun_add_history() {
    local EXIT_CODE=$?
    local CMD=$(fc -ln -1)
    # Run in background to avoid latency
    hun add --cmd "$CMD" --cwd "$PWD" --exit-code "$EXIT_CODE" &!
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd hun_add_history

# Bind Ctrl+R to Hun Search
function hun_search() {
    local SELECTED_CMD=$(hun search --query "$BUFFER")
    if [ -n "$SELECTED_CMD" ]; then
        BUFFER="$SELECTED_CMD"
        CURSOR=$#BUFFER
    fi
    zle redisplay
}
zle -N hun_search
bindkey "^R" hun_search

Bash

Add the following to your ~/.bashrc:

# Hun Integration
function hun_add_history() {
    local EXIT_CODE=$?
    local CMD=$(history 1 | sed 's/^[ ]*[0-9]\+[ ]*//')
    hun add --cmd "$CMD" --cwd "$PWD" --exit-code "$EXIT_CODE" &
}

PROMPT_COMMAND="hun_add_history; $PROMPT_COMMAND"

# Bind Ctrl+R to Hun Search
bind -x '"\C-r": "READLINE_LINE=$(hun search --query \"$READLINE_LINE\") && READLINE_POINT=${#READLINE_LINE}"'

Usage

Search History

Press Ctrl+R (if configured) or run:

hun search
  • Type to filter.
  • Up/Down to navigate.
  • Enter to select.
  • Esc to cancel.

View Stats

See your top 10 most used commands:

hun stats

Manual Add

You generally don't need this, but you can add entries manually:

hun add --cmd "echo hello" --cwd "/tmp" --exit-code 0

License

MIT

Commit count: 0

cargo fmt