Fuzzy autocorrect for mistyped Linux/macOS shell commands. Works in bash and zsh.
Reason this release was yanked:
out of date
Project description
lk-autocorrect
Fuzzy autocorrect for mistyped shell commands. Works in zsh and bash on Linux and macOS.
When you mistype a command, instead of a dead error you get a suggestion:
$ gti status
[lk-autocorrect] Did you mean: git status?
[lk-autocorrect] Run it? [y/N] y
$ dockr ps
[lk-autocorrect] Did you mean: docker ps?
[lk-autocorrect] Run it? [y/N] y
$ terrafrom plan
[lk-autocorrect] Did you mean: terraform plan?
[lk-autocorrect] Run it? [y/N] y
Requirements
- macOS or Linux
- Python 3.9+ — check with
python3 --version - zsh or bash — check with
echo $SHELL
Windows is not supported natively. Use WSL (Windows Subsystem for Linux) and follow the Linux instructions.
Install
Step 1 — Install lk-autocorrect
pip install lk-autocorrect
macOS users: if you see an
externally-managed-environmenterror, use:pip install lk-autocorrect --user --break-system-packages
Step 2 — Run the installer
lk-autocorrect install
This automatically adds the source line to your ~/.zshrc or ~/.bashrc.
Step 3 — Reload your shell
source ~/.zshrc # zsh
source ~/.bashrc # bash
Step 4 — Test it
gti status # → Did you mean: git status?
dockr ps # → Did you mean: docker ps?
kubctl get pods # → Did you mean: kubectl get pods?
Shell compatibility
| Shell | Support | Notes |
|---|---|---|
| zsh | Full | Automatic — fires on any mistyped command |
| bash 4+ | Full | Automatic — fires on any mistyped command |
| bash 3.2 | Partial | Use lk <command> as fallback |
bash 3.2 on macOS
This version does not support the command_not_found_handle hook that lk-autocorrect relies on for automatic correction.
When you source the script in bash 3.2 you will see:
[lk-autocorrect] bash 3.2 detected — automatic correction unavailable.
[lk-autocorrect] Use: lk <command> e.g. lk gti status
[lk-autocorrect] Or switch to zsh: chsh -s /bin/zsh
Option 1 — use the lk fallback:
lk gti status # → Did you mean: git status?
lk dockr ps # → Did you mean: docker ps?
Option 2 — switch to zsh (recommended):
chsh -s /bin/zsh
# open a new terminal — autocorrect works automatically
Option 3 — upgrade bash:
brew install bash
echo '/opt/homebrew/bin/bash' | sudo tee -a /etc/shells
chsh -s /opt/homebrew/bin/bash
Python version
lk-autocorrect requires Python 3.9+ and is supported on older versions, but upgrading to 3.13+ is recommended since older versions no longer receive security patches.
Check your version:
python3 --version
Upgrade on macOS:
brew install python@3.13
Upgrade on Linux:
sudo apt install python3.13
Usage
Once installed, autocorrect fires automatically whenever you mistype a command:
$ gti commit -m "fix bug"
[lk-autocorrect] Did you mean: git commit -m "fix bug"?
[lk-autocorrect] Run it? [y/N] y
Shell commands
| Command | Description |
|---|---|
ac-add <cmd> |
Add a command to the store |
ac-remove <cmd> |
Remove a command from the store |
ac-list |
List all commands in the store |
ac-test <typo> |
Preview what a typo would correct to |
ac-help |
Show in-shell help |
# add your own commands
ac-add "mycli"
ac-add "my-test-command"
# preview a correction
ac-test "dockr"
# [lk-autocorrect] 'dockr' → 'docker' (distance: 1)
# list everything in the store
ac-list
CLI commands
| Command | Description |
|---|---|
lk-autocorrect install |
Install and set up shell hook |
lk-autocorrect uninstall |
Remove from system |
lk-autocorrect status |
Show installation status |
lk-autocorrect verify |
Check file integrity and print checksums |
lk-autocorrect help |
Show help |
Configuration
Set these in your ~/.zshrc or ~/.bashrc before the source line:
# how forgiving the matcher is (1 = strict, 5 = loose) — default: 3
export AUTOCORRECT_THRESHOLD=2
# auto-run the correction without asking — default: false
export AUTOCORRECT_AUTO=true
# turn off colours — default: true
export AUTOCORRECT_COLOR=false
Command store
The store lives at ~/.config/lk-autocorrect/commands.txt — one command per line, # lines are comments.
Ships with 150+ popular commands across git, docker, kubectl, terraform, AWS CLI, Azure CLI and more. Your store is preserved across updates and uninstalls (you are asked before it is deleted).
# add a command
ac-add "mycli"
# remove a command
ac-remove "mycli"
# or edit directly
nano ~/.config/lk-autocorrect/commands.txt
How it works
- The shell hook (
command_not_found_handlerin zsh,command_not_found_handlein bash 4+) fires when a command is not found. - The typo is passed to
matcher.pywhich compares it against every command in the store using Damerau-Levenshtein distance — an algorithm that counts insertions, deletions, substitutions, and transpositions. This meansgti→gitscores as distance 1 (one transposition) not 2. - If the closest match is within
AUTOCORRECT_THRESHOLDedits, the suggestion is shown. - You confirm with
yor it runs automatically ifAUTOCORRECT_AUTO=true.
Update
pip install lk-autocorrect --upgrade
Uninstall
lk-autocorrect uninstall
pip uninstall lk-autocorrect
Verify integrity
lk-autocorrect verify
Prints the SHA256 checksums of the installed files so you can verify them against the GitHub release.
Contributing
Pull requests welcome.
- Fork the repo
- Create a branch:
git checkout -b my-feature - Make changes to
src/autocorrect.shorsrc/matcher.py - Test in both zsh and bash
- Open a PR
License
MIT — see LICENSE
Named in memory of L.K.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lk_autocorrect-1.1.0.tar.gz.
File metadata
- Download URL: lk_autocorrect-1.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28dd5426623e2bb18abb2e30795aa2dfe7ad8b3e73b2892409b40178951a83a4
|
|
| MD5 |
68eb6828d4b01f0f0da156b065638171
|
|
| BLAKE2b-256 |
a9c366abbaa66fd51b5e7e2faa15b515bb156ae827ce5a0e9f6c7b4b0fe6ee09
|
File details
Details for the file lk_autocorrect-1.1.0-py3-none-any.whl.
File metadata
- Download URL: lk_autocorrect-1.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
537f319a762a413d1701eb65a4df5173f46e005397bb7697ff33de4663c0d0c6
|
|
| MD5 |
e8d509887b679eb356e8db744809d2b3
|
|
| BLAKE2b-256 |
ccd2c525ab55da53fcb810c9f33ac9fd72fc132889ea1e3811e510127b1a6443
|