5 unstable releases
new 0.4.1 | Mar 2, 2025 |
---|---|
0.3.1 | Mar 2, 2025 |
0.3.0 | Mar 2, 2025 |
0.1.1 | Mar 2, 2025 |
0.1.0 | Feb 28, 2025 |
#327 in Development tools
110 downloads per month
140KB
2K
SLoC
๐บ Super Snoofer
A fuzzy command finder for shells that suggests and executes similar commands when a typo is made. When you mistype a command, Super Snoofer will suggest the closest matching command and offer to execute it for you.
$ gti status
Awoo! ๐บ Did you mean `git status`? *wags tail* (Y/n/c) y
Running suggested command...
โจ Features
- ๐ Fuzzy command matching using Levenshtein distance
- ๐ Fast command lookup with cached command list
- ๐ Colorful and friendly interface
- ๐ Automatic command execution on confirmation
- ๐ง Command learning for frequently used corrections
- ๐ Support for Python scripts (both .py and without extension)
- ๐พ Persistent command cache
- ๐ Safe command execution through user's shell
- โก Parallel command matching using Rayon
- ๐ Shell alias detection and fuzzy matching for Bash, Zsh, and Fish
- ๐ฎ Full command line correction including arguments and flags for well-known commands
- ๐ต๏ธ History tracking that can be enabled or disabled for privacy
- ๐งฉ Smart shell configuration for creating and managing aliases
- ๐ Enhanced typo correction for common commands like Git
๐ฆ Installation
From crates.io
cargo install super_snoofer
From Source
git clone https://github.com/rakki194/super_snoofer.git
cd super_snoofer
cargo install --path .
๐ง Setup
ZSH Integration
Add this to your ~/.zshrc
:
command_not_found_handler() {
super_snoofer "$1"
return $?
}
Bash Integration
Add this to your ~/.bashrc
:
command_not_found_handle() {
super_snoofer "$1"
return $?
}
Fish Integration
Create a function in ~/.config/fish/functions/fish_command_not_found.fish
:
function fish_command_not_found
super_snoofer "$argv[1]"
return $status
end
๐ฏ Usage
Super Snoofer works automatically once integrated with your shell. When you type a command that doesn't exist, it will:
- Search for similar commands in your PATH
- If a match is found, suggest it with a friendly prompt
- You can:
- Press Enter or 'y' to accept and execute the suggestion
- Press 'n' to reject the suggestion
- Press 'c' to teach Super Snoofer the correct command
- Exit with the appropriate status code
Command Line Options
super_snoofer <command> # Normal operation: suggest similar commands
super_snoofer --reset_cache # Clear the command cache but keep learned corrections
super_snoofer --reset_memory # Clear both the command cache and learned corrections
super_snoofer --history # Display your recent command corrections
super_snoofer --frequent-typos # Display your most common typos
super_snoofer --frequent-corrections # Display your most frequently used corrections
super_snoofer --clear-history # Clear your command history
super_snoofer --enable-history # Enable command history tracking
super_snoofer --disable-history # Disable command history tracking
super_snoofer --suggest # Suggest personalized shell aliases
Example Interactions
# Basic suggestion and execution
$ carg build
Awoo! ๐บ Did you mean `cargo`? *wags tail* (Y/n/c) y
Running suggested command...
Compiling super_snoofer v0.1.0
# Teaching Super Snoofer a correction
$ gti status
Awoo! ๐บ Did you mean `got`? *wags tail* (Y/n/c) c
What's the correct command? git
Got it! ๐บ I'll remember that 'gti' means 'git'
[git output follows...]
# Using a learned correction
$ gti status
Awoo! ๐บ Did you mean `git`? *wags tail* (Y/n/c) y
Running suggested command...
[git output follows...]
# Rejecting a suggestion
$ pythn
Awoo! ๐บ Did you mean `python`? *wags tail* (Y/n/c) n
Command 'pythn' not found! ๐บ
โ๏ธ Configuration
Super Snoofer stores its data in:
~/.cache/super_snoofer_cache.json
(if ~/.cache exists)~/.super_snoofer_cache.json
(fallback)
The cache contains:
- List of available commands in your PATH (refreshed daily)
- Learned command corrections (persistent unless cleared)
- Command execution history
Cache Management:
- The command cache is automatically cleared and rebuilt every 24 hours
- Learned corrections persist across cache resets
- Use
--reset_cache
to manually clear the command cache - Use
--reset_memory
to clear both cache and learned corrections
๐ฌ Technical Details
Command Learning
Super Snoofer can learn from your corrections:
- When a suggestion is wrong, press 'c' to teach it the right command
- Learned corrections take precedence over fuzzy matching
- Corrections are persisted in the cache file
- Only valid commands can be learned as corrections
- Learned corrections are ~500x faster than fuzzy matching
Performance
Command matching performance (on typical systems):
- Learned corrections: ~30 nanoseconds
- Fuzzy matching (exact or typo): ~16 microseconds
- Cache updates: performed asynchronously to minimize latency
This means:
- Learned corrections are nearly instant
- Fuzzy matching is fast enough for interactive use
- The more you teach Super Snoofer, the faster it gets
Similarity Matching
Super Snoofer uses the Levenshtein distance algorithm to find similar commands, with a configurable similarity threshold (currently set to 0.6). This means:
- Commands must be at least 60% similar to be suggested
- Matches are found based on character-level differences
- The most similar command is always suggested first
Command Discovery
Super Snoofer finds commands by:
-
Scanning all directories in your PATH:
- Finds executable files
- Follows symbolic links (including multi-level and circular links)
- Adds both symlink names and their targets to the command list
- Handles relative and absolute symlink paths
-
Special handling for Python:
- Discovers Python executables (python, python3, etc.)
- Finds executable Python scripts in Python directories
- Adds both .py and non-.py versions of script names
-
Command caching:
- Caches discovered commands for better performance
- Updates cache daily or on manual reset
- Preserves learned corrections across cache updates
Symlink Resolution
Super Snoofer handles symbolic links intelligently:
- Follows multi-level symlink chains (e.g.,
python -> python3 -> python3.13
) - Adds all names in the symlink chain to the command list
- Handles both relative and absolute symlink paths
- Detects and safely handles circular symlinks
- Preserves symlink-based command aliases
For example, if you have:
/usr/bin/python3.13 # Actual executable
/usr/bin/python3 -> python3.13
/usr/bin/python -> python3
Super Snoofer will suggest any of these names when you make a typo:
$ pythn
Awoo! ๐บ Did you mean `python`? *wags tail* (Y/n/c)
$ pythn3
Awoo! ๐บ Did you mean `python3`? *wags tail* (Y/n/c)
$ python313
Awoo! ๐บ Did you mean `python3.13`? *wags tail* (Y/n/c)
Security
- Commands are always executed through the user's shell
- No commands are executed without user confirmation
- The cache file uses standard file permissions
- Command execution preserves arguments and exit codes
๐ค Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch
- Make your changes
- Add or update tests
- Submit a pull request
Please make sure to:
- Follow the existing code style
- Add tests for new functionality
- Update documentation as needed
๐งช Testing
Run the test suite:
cargo test
The test suite includes:
- Unit tests for command matching
- Integration tests for command execution
- Command learning and persistence tests
- Cache handling tests
- Path resolution tests
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- strsim for Levenshtein distance calculation
- colored for terminal colors
- rayon for parallel processing
- walkdir for filesystem traversal
๐ Troubleshooting
Common Issues
-
Command not found after installation
- Ensure
~/.cargo/bin
is in your PATH - Try running
source ~/.bashrc
or equivalent
- Ensure
-
Cache not updating
- Check file permissions in ~/.cache
- Try removing the cache file manually
-
No suggestions appearing
- Verify shell integration is properly set up
- Check if the command exists in your PATH
Getting Help
If you encounter issues:
- Check the Issues page
- Include relevant error messages and your environment details
- Describe the steps to reproduce the problem
Shell Aliases
Super Snoofer now detects and includes shell aliases in its suggestions:
- Automatically finds and loads aliases from:
- Bash:
.bashrc
and.bash_aliases
- Zsh:
.zshrc
,.zsh_aliases
, and Oh-My-Zsh custom aliases - Fish:
config.fish
and function-based aliases in~/.config/fish/functions/
- Bash:
- Updates the alias cache every 24 hours
- Shows both the alias name and the command it represents
- Provides fuzzy matching for aliases just like regular commands
Alias Matching Examples
Here are some useful examples of how Super Snoofer matches and suggests aliases:
# Example 1: Mistyped alias corrected to original alias
$ kk stutus # Where kk is an alias for kubectl
Awoo! ๐บ Did you mean `kk` (alias for `kubectl`)? *wags tail* (Y/n/c) y
Running suggested command: kubectl status
[command output follows...]
# Example 2: Mistyped alias suggesting multiple possibilities
$ dc ps # When you have both 'dc' and 'dco' as aliases
Awoo! ๐บ Did you mean `dc` (alias for `docker-compose`)? *wags tail* (Y/n/c) y
Running suggested command: docker-compose ps
[command output follows...]
# Example 3: Related aliases for common commands
$ giff # When you have git-related aliases
Awoo! ๐บ Did you mean `giff` (alias for `git diff --color`)? *wags tail* (Y/n/c) y
[git diff output follows...]
# Example 4: Learning a correction for a complex alias
$ dkr-rmall
Awoo! ๐บ Did you mean `dkr` (alias for `docker`)? *wags tail* (Y/n/c) c
What's the correct command? drm-all
Got it! ๐บ I'll remember that 'dkr-rmall' means 'drm-all'
[docker remove all containers output follows...]
# Example 5: Nested alias resolution
$ gs # Where gs is an alias for 'git status'
Awoo! ๐บ Did you mean `gs` (alias for `git status`)? *wags tail* (Y/n/c) y
[git status output follows...]
Benefits of Alias Matching
Alias matching in Super Snoofer provides several advantages:
- Consistency - Get suggestions for both commands and their aliases
- Discoverability - Learn about available aliases in your system
- Convenience - See what command an alias actually runs
- Context awareness - Suggestions are tailored to your shell setup
Aliases are treated as first-class commands in Super Snoofer, meaning:
- You get suggestions for typos of aliases
- The underlying command is shown in the suggestion
- Aliases can be learned as corrections just like regular commands
- Aliases are included in fuzzy matching searches
๐ Command History & Frequency Analysis
Super Snoofer is a good boy and will try to learn from your mistakes, by tracking the history of your command corrections and typos to provide smarter suggestions over time:
- Command history tracking - Records all command corrections and queries
- Frequency analysis - Suggests more commonly used commands first
- Pattern recognition - Learns your specific typing patterns and common mistakes
- Personalized suggestions - Tailors suggestions based on your command usage history
History Features
# View your command correction history
$ super_snoofer --history
๐บ Your recent command corrections:
1. gti โ git (17 times)
2. pythno โ python (8 times)
3. docekr โ docker (5 times)
...
# View most frequent typos
$ super_snoofer --frequent-typos
๐บ Your most common typos:
1. gti (17 times)
2. pythno (8 times)
3. docekr (5 times)
...
# View most frequent corrections
$ super_snoofer --frequent-corrections
๐บ Your most frequently used corrections:
1. git (22 times)
2. python (15 times)
3. docker (11 times)
...
# Clear your command history
$ super_snoofer --clear-history
Command history cleared successfully! ๐บ
# Enable command history tracking
$ super_snoofer --enable-history
Command history tracking is now enabled! ๐บ
# Disable command history tracking
$ super_snoofer --disable-history
super_snoofer --add-alias NAME [CMD] # Add shell alias (default: super_snoofer)
Command history tracking is now disabled! ๐บ
When making suggestions, Super Snoofer now prioritizes commands based on your usage history:
# When typing a command with multiple possible corrections
$ gti
Awoo! ๐บ Did you mean `git` (used 17 times)? *wags tail* (Y/n/c) y
Running suggested command...
The history data is stored in your cache file and is used to:
- Prioritize frequently used commands in suggestions
- Identify patterns in your typing mistakes
- Improve suggestion accuracy over time
- Provide insights into your command usage habits
This feature helps Super Snoofer become more personalized to your workflow the more you use it.
History Control
Super Snoofer allows you to control whether command history is tracked:
- History Tracking Enabled (default): Super Snoofer records all typos and corrections to provide increasingly personalized suggestions over time
- History Tracking Disabled: No command history is recorded, providing more privacy but without the benefits of personalized suggestions
You can toggle this setting using the following commands:
# Disable history tracking
$ super_snoofer --disable-history
Command history tracking is now disabled! ๐บ
# Enable history tracking
$ super_snoofer --enable-history
Command history tracking is now enabled! ๐บ
When history tracking is disabled:
- No new command corrections will be recorded
- Frequency analysis will not be updated
- Existing learned corrections will still be used
- The
--history
,--frequent-typos
, and--frequent-corrections
commands will inform you that history tracking is disabled
This feature is useful if you:
- Are concerned about privacy
- Share your computer with others
- Want to prevent recording sensitive commands
- Prefer not to have personalized suggestions
The setting persists between Super Snoofer sessions.
๐ง Personalized Alias Suggestions
Super Snoofer can analyze your command history and suggest helpful aliases to save you time:
# Generate a personalized alias suggestion
$ super_snoofer --suggest
You've mistyped 'gti' 17 times! Let's create an alias for that.
Suggested alias: g โ git
To add this alias to your shell configuration:
alias g='git'
Would you like me to add this alias to your shell configuration? (y/N)
The --suggest
command analyzes your command history to:
- Identify your most common typos
- Recommend useful aliases based on your usage patterns
- Offer to automatically add the aliases to your shell configuration
- Create shortcuts for your most frequently used commands
This feature helps you create a more efficient workflow by automating the creation of aliases tailored to your specific typing patterns and command usage.
๐ฎ Full Command Line Correction
Super Snoofer v0.3.0 now corrects typos in the entire command line, not just the command name. For well-known commands, it can intelligently fix typos in subcommands, arguments, and flags:
# Correcting typos in git commands
$ gti sttaus
Awoo! ๐บ Did you mean `git status`? *wags tail* (Y/n/c) y
Running suggested command...
# Correcting typos in docker commands
$ dockr ps -a
Awoo! ๐บ Did you mean `docker ps -a`? *wags tail* (Y/n/c) y
Running suggested command...
# Correcting typos in cargo commands and flags
$ carg buld --relese
Awoo! ๐บ Did you mean `cargo build --release`? *wags tail* (Y/n/c) y
Running suggested command...
Enhanced Typo Correction
Super Snoofer v0.3.0 includes special handling for common Git command typos, such as:
# Common "status" typos
$ gti statuus
Awoo! ๐บ Did you mean `git status`? *wags tail* (Y/n/c) y
Running suggested command...
$ git satatus
Awoo! ๐บ Did you mean `git status`? *wags tail* (Y/n/c) y
Running suggested command...
$ git statsu
Awoo! ๐บ Did you mean `git status`? *wags tail* (Y/n/c) y
Running suggested command...
The correction engine is especially tuned for:
- Common Git operations (status, commit, push, pull)
- Docker commands (run, build, ps)
- Cargo commands (build, run, test)
- npm commands (install, run)
- kubectl commands
Super Snoofer uses a combination of pattern matching, Levenshtein distance, and special case handling to provide highly accurate corrections for these common command patterns.
Supported Commands
Super Snoofer includes built-in knowledge about these common commands and their arguments:
- Git: status, commit, push, pull, branch, merge, etc.
- Docker: run, build, ps, exec, logs, etc.
- Cargo: build, run, test, check, publish, etc.
- npm: install, uninstall, update, run, etc.
- kubectl: get, describe, apply, delete, logs, etc.
How It Works
When you enter a command with typos:
- Super Snoofer first corrects the base command (e.g., "gti" โ "git")
- For well-known commands, it then attempts to correct each argument and flag
- For arguments, it checks against known subcommands (e.g., "sttaus" โ "status")
- For flags, it checks against known options (e.g., "--hlp" โ "--help")
- It presents the fully corrected command line for your approval
This works best with common CLI tools, but will fall back to simple command correction for other commands.
๐งฉ Smart Shell Configuration
Super Snoofer includes intelligent shell detection and configuration management features that make it easy to add aliases and integrate with your system:
Automatic Shell Detection
Super Snoofer can detect your current shell environment and provide appropriate configuration instructions:
# When suggesting an alias
$ super_snoofer --suggest
You've mistyped 'gti' 17 times! Let's create an alias for that.
Suggested alias: g โ git
To add this alias to your shell configuration:
alias g='git'
Would you like me to add this alias to your Zsh shell configuration? (y/N) y
Adding alias to /home/user/.zshrc
Added alias to your Zsh configuration! ๐บ Please run 'source /home/user/.zshrc' to use it.
Supported Shells
Super Snoofer automatically detects and supports:
- ๐ Bash - Configures
.bashrc
- ๐ฎ Zsh - Configures
.zshrc
- ๐ Fish - Configures
config.fish
- ๐ป PowerShell - Configures profile script
- ๐ต Nushell - Configures
config.nu
- ๐ Korn Shell - Configures
.kshrc
- ๐ C Shell/TCSH - Configures
.cshrc
or.tcshrc
- ๐ช Windows Command Prompt - Configures doskey batch file
Configuration Files
Super Snoofer creates appropriate shell-specific alias syntax based on your shell:
Shell | Configuration File | Alias Format |
---|---|---|
Bash | ~/.bashrc | alias g='git' |
Zsh | ~/.zshrc | alias g='git' |
Fish | ~/.config/fish/config.fish | alias g 'git' |
PowerShell | ~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1 | Set-Alias -Name g -Value git |
Nushell | ~/.config/nushell/config.nu | alias g = git |
Korn Shell | ~/.kshrc | alias g='git' |
C Shell/TCSH | ~/.cshrc or ~/.tcshrc | alias g 'git' |
Windows CMD | %USERPROFILE%\doskey.bat | doskey g=git |
Shell Integration With Auto-Setup
Super Snoofer can not only suggest aliases but also handle the entire configuration process for you:
- Detects your current shell environment automatically
- Creates appropriate configuration files if they don't exist
- Adds shell-specific syntax for aliases and functions
- Preserves existing content in configuration files
- Suggests reload commands after configuration changes
This makes it simple to integrate Super Snoofer with your workflow without needing to remember shell-specific configuration details.
Dependencies
~8โ19MB
~281K SLoC