GitHub - Schachte/Historian: A better reverse-search tool for shell history

2 min read Original article ↗

Historian

UI

Shell history manager with SQLite backend.

Demo

demo.mov

Installation

make build 
make install

# install hook so historian can intercept and store commands
historian hook --install --shell zsh

# source session or make a new window
source ~/.zshrc

# import existing shell history
historian import -history ~/.zsh_history
# Example output: Imported 0 commands from /Users/schachte/.zsh_history (10078 parsed, 10078 skipped as duplicates)

Usage

Initialize

historian init [--config PATH] [--db PATH] [--force] [--debug]

Log commands

historian log --command "ls -la" [--exit CODE] [--session ID] [--phase start|end|complete] [--id ID]

Search history

# Interactive search
historian search

# Raw output
historian search --raw [--query TEXT] [--limit N] [--session ID] [--cursor POS] [--debug]

Shell integration

# Print hook for current shell
historian hook

# Install hook
historian hook --install [--shell bash|zsh] [--rc PATH]

Import history

historian import [--history PATH] [--user USER] [--host HOST] [--session ID]

Destroy database

SQLite Direct Query

Default database location:

~/.local/share/historian/history.sqlite3

Schema:

CREATE TABLE commands (
  id INTEGER PRIMARY KEY,
  command TEXT NOT NULL,
  run_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  finished_at TIMESTAMP,
  duration_ms INTEGER,
  username TEXT NOT NULL,
  hostname TEXT NOT NULL,
  cwd TEXT NOT NULL,
  exit_code INTEGER,
  session_id TEXT
);

Query examples:

sqlite3 ~/.local/share/historian/history.sqlite3 "SELECT * FROM commands ORDER BY run_at DESC LIMIT 10;"
sqlite3 ~/.local/share/historian/history.sqlite3 "SELECT command, run_at FROM commands WHERE command LIKE '%git%';"