The zsh-histdb plugin provides advanced shell history management by storing Zsh command history in a SQLite database. This enables enhanced querying, sorting, and pattern-based history recall, far beyond the default .zsh_history capabilities.
The plugin is installed using Git during the Docker build process:
# Installed into the custom plugins folder
$ git clone https://github.com/larkery/zsh-histdb.git ${ZSH_CUSTOM:-~/.zsh/custom}/plugins/zsh-histdbAdditionally, the following two scripts are sourced in .zshrc:
source $ZSH/custom/plugins/zsh-histdb/sqlite-history.zsh
source $ZSH/custom/plugins/zsh-histdb/histdb-interactive.zshTo enable context-aware autosuggestions based on historical frequency and location, the following custom strategies are defined in .sh_functions:
Returns the most frequent command used in the current directory or below that matches the user's input.
Returns the most frequent command used globally, sorted by frequency but giving preference to the current directory.
Fallback strategy that prioritizes local history if matches exist; otherwise, defaults to global history.
These strategies are compatible with zsh-autosuggestions when the variable is configured:
ZSH_AUTOSUGGEST_STRATEGY=histdb_top_hereThe plugin includes an interactive search interface, accessible via the histdb-interactive.zsh script. This allows fuzzy searching through history with context.
Custom helper functions provided in .sh_functions include:
Displays the most recent commands used in the current directory.
Searches for a pattern in the local directory’s command history.
Returns globally used commands matching a prefix, ordered by recency.
History is stored in ~/.histdb/zsh-history.db, which is mounted in the DevContainer and versioned in this example for educational purposes.
By combining zsh-histdb with autosuggestions and custom strategies, this project enables a more intelligent, context-aware shell experience. This plugin is particularly valuable for workflows involving frequent command reuse or project-specific history navigation.