Git Command Typo Highlighter

git-highlight is a Zsh plugin that highlights your Git commands in real-time. It highlights valid and partially matched Git subcommands, and flags invalid ones right away.

Real-time Highlights

See your Git commands highlighted instantly as you type for avoiding mistakes.

Any Platform

Zsh works on any platform including macOS, Linux, and Windows.

Customizable

Tailor the plugin to your workflow with powerful customization options.

Example

Typing: git sta will highlight git in green and sta in yellow, hinting that you meant status.

Once you complete it to: git status, both words will be in green, confirming a valid command.

git stats, will highlight stats in red.

Git Command Highlighting Is the Satisfaction You Didn't Know You Wanted

Get Started

Installation

  1. Clone the repository:
    git clone https://github.com/patriciosebastian/git-highlight.git ~/.git-highlight
  2. Add the script to your .zshrc file:

    This will source the git-highlight script on every new Zsh session, ensuring the highlighting feature is always active.

    echo "source ~/.git-highlight/git-highlight.zsh" >> ~/.zshrc
    source ~/.zshrc

    If you'd rather add it manually, just open your .zshrc (located in your home directory) and append:

    source ~/.git-highlight/git-highlight.zsh
  3. Refresh your terminal (close and reopen, or run source ~/.zshrc again).

From now on, every new Zsh terminal session will have real-time Git command highlighting enabled.

Locating Your .zshrc File

Your .zshrc file is typically located in your home directory (~/.zshrc). On macOS and Linux, you can access it by running:

cd ~
ls -a

If you see .zshrc listed, you can open it with your favorite text editor. If it doesn't exist, you can create one:

touch ~/.zshrc

Windows users running Zsh in WSL will also find their .zshrc file in the Linux home directory, e.g., ~/ within their WSL environment.

Using a Zsh Plugin Manager

  1. If you're using a Zsh plugin manager like zplug, just add:
    zplug "patriciosebastian/git-highlight"

Customization

Inside git-highlight.zsh, you'll find:

**Git Commands:**

  1. Modify the validGitCommands array to add or remove recognized commands:
    typeset -a validGitCommands=(git init commit push pull status checkout merge branch fetch rebase diff add log stash pop restore reset)
  2. Add more (optional):
    validGitCommands+=(blame cherry-pick worktree)
  3. Shell Operators. If you want to add more of fewer operators, update the case block:
    case "$word" in
      '&&'|'||'|';'|'&')
        expect_subcommand=false
        ;;
    esac

Feel Free to tweak these as needed for your workflow.

Like this tool? Find it helpful?

Consider buying me a coffee to support my work.