migu-0.1.0 is not a library.
migu — Cross-Shell Command History Manager
命名自《山海经》迷榖:"有木焉,其状如谷而黑理,其华四照,其名曰迷穀,佩之不迷。"。migu records your shell commands into a local SQLite database and provides an interactive TUI browser for fast recall.
Supports bash, zsh, fish.
Features
- Persistent history — all commands stored in SQLite
- Interactive TUI — fuzzy search, keyboard navigation, two sort modes
- Time mode — most recent commands (consecutive duplicates folded)
- Frequency mode — most used commands (grouped by command + directory)
- cwd-aware — commands from current directory shown first
- Instant record — WAL-mode SQLite, sub-millisecond writes
Quick Start
Install
Setup (bash)
This sets up:
PROMPT_COMMANDto auto-record every command- Ctrl-R keybinding for the TUI browser
Restart your shell or add to ~/.bashrc:
# ~/.bashrc
Usage
Browse history
Press Ctrl-R to open the TUI browser:
> cvbnm │ 跳转:15_
1/30 ────────────────────────────────────────────────────
1. git status ~/re (2分钟前)
2. cargo build --release ~/re (5分钟前)
3. ssh prod-server ~ (12分钟前)
30. cat /var/log/syslog /var (1天前)
Keys
| Key | Action |
|---|---|
↑ ↓ |
Navigate |
| Enter | Execute selected command |
| Tab | Insert command into prompt (editable) |
| Alt + s | Toggle Time / Frequency mode |
| Alt + n | Enter number-input mode, digits + Enter to jump |
| Alt + l | Change display limit |
| Alt + h | Show help |
← → Home End |
Move cursor in search bar |
Backspace / Delete |
Edit search text |
| Type any text | Fuzzy filter |
PgUp / PgDn |
Page scroll |
Esc / Ctrl-C |
Quit |
Direct invocation
Commands
| Command | Description |
|---|---|
migu |
Launch TUI browser |
migu add -- <command> |
Record a command (called by shell hooks) |
migu init <shell> |
Output shell configuration (bash / zsh / fish) |
migu -n <N> |
Set max results (default 30, max 100) |
migu --no-dedup |
Show all entries without dedup |
Shell Integration
Bash
# Auto-record
PROMPT_COMMAND=_migu_prompt_command
# Ctrl-R binding
Zsh
Fish
function _migu_add --on-event fish_preexec
if set -q _migu_skip
return
end
set -g _migu_skip 1
migu add -- "$argv"
set -e _migu_skip
end
function _migu_widget
MIGU_WIDGET=1 command migu
set -l cmd (cat /tmp/migu-cmd 2>/dev/null)
rm -f /tmp/migu-cmd
commandline -r -- $cmd
end
bind \cr _migu_widget
Database
Location: ~/.local/share/migu/history.db (SQLite, WAL mode)
Auto-purges to 100,000 entries (configurable via MIGU_MAX_ENTRIES env var).
Build
Requirements: Rust 1.70+
Dependencies: rusqlite, clap, ratatui, crossterm, chrono, dirs, libc, rand, shell-words, whoami