A command-line tool to semantically search your shell command history using OpenAI embeddings. Find commands based on natural language descriptions instead of exact text matches. Supports multiple shells including Bash, Zsh, and Fish.
- Semantic search using OpenAI embeddings
- Supports multiple shell history files (Bash, Zsh, Fish)
- Deduplicates commands across different shells
- Persists embeddings locally for fast subsequent searches
- Shows similarity scores for each result
- Supports refreshing the database with latest history
- Python 3.8+
- OpenAI API key
- One or more of these shells installed:
- Bash (
~/.bash_history
) - Zsh (
~/.zsh_history
) - Fish (
~/.local/share/fish/fish_history
)
- Bash (
- Clone this repository:
git clone https://github.com/yourusername/bash-history-search.git
cd bash-history-search
- Install dependencies:
pip install -r requirements.txt
- Create a
.env
file in the project root and add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
Basic search:
python bash_search.py "find files containing text"
Search with custom number of results:
python bash_search.py "git commands" --num 10
Refresh the database with latest shell history:
python bash_search.py "your query" --refresh
- The tool reads command history from multiple sources:
- Bash history from
~/.bash_history
- Zsh history from
~/.zsh_history
- Fish history from
~/.local/share/fish/fish_history
- Bash history from
- Commands are deduplicated across all sources
- Each unique command is embedded using OpenAI's text-embedding-3-small model
- Embeddings are stored locally using ChromaDB
- When searching, your query is embedded and compared with stored command embeddings
- Most similar commands are returned with their similarity scores
query
: Your search query in natural language (required)--num
,-n
: Number of results to return (default: 5)--refresh
,-r
: Refresh the database with latest shell history
Most similar commands:
grep -r "search text" .
Similarity: 0.892
find . -type f -exec grep "pattern" {} \;
Similarity: 0.857
ag "search string" --ignore-dir node_modules
Similarity: 0.843
The tool will automatically look for history files in these default locations:
- Bash:
~/.bash_history
- Zsh:
~/.zsh_history
- Fish:
~/.local/share/fish/fish_history
If your shell history files are in different locations, you can modify the paths in the code.
MIT