Skip to main content

Fuzzy autocorrect for mistyped Linux/macOS shell commands. Works in bash and zsh.

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-environment error, 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: 2
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

  1. The shell hook (command_not_found_handler in zsh, command_not_found_handle in bash 4+) fires when a command is not found.
  2. The typo is passed to matcher.py which compares it against every command in the store using Damerau-Levenshtein distance — an algorithm that counts insertions, deletions, substitutions, and transpositions. This means gtigit scores as distance 1 (one transposition) not 2.
  3. If the closest match is within AUTOCORRECT_THRESHOLD edits, the suggestion is shown.
  4. You confirm with y or it runs automatically if AUTOCORRECT_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.

  1. Fork the repo
  2. Create a branch: git checkout -b my-feature
  3. Make changes to src/autocorrect.sh or src/matcher.py
  4. Test in both zsh and bash
  5. Open a PR

License

MIT — see LICENSE


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lk_autocorrect-1.2.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lk_autocorrect-1.2.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file lk_autocorrect-1.2.0.tar.gz.

File metadata

  • Download URL: lk_autocorrect-1.2.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for lk_autocorrect-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7bbab62c9c520edc9a0adecd97a865698abc123c7e3bdd86164c809e3207fc8a
MD5 12c635881f58063e387a59033809b1be
BLAKE2b-256 cfe5a1a28bf05dc283f949e5a969a5af6c737b77b08ed94246916dd5c821dc69

See more details on using hashes here.

File details

Details for the file lk_autocorrect-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: lk_autocorrect-1.2.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

Hashes for lk_autocorrect-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11962aaa4afe54e5d5a920d966d7cc16af17d5f3a4d663464069617c94e3c17c
MD5 cccfdd8073318526fa546f176f5defa2
BLAKE2b-256 d27b5b5d629f628daa16f596abcda0c3c467d7b41afadc6fcdd5a86f72ddd36a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page