Just autocomplete and git alias autocomplete aren't working with zsh and homebrew
Asked Answered
M

1

1

For the longest time I couldn't get justfile's just commands to autocomplete. I finally found a way to get just to work. But then, because of Homebrew, it appears to be breaking my git alias autocomplete.

Example:

  • I type "git " and then "tab" and none of my aliases in .gitconfig show
Martel answered 7/1 at 21:7 Comment(0)
M
1

Here is a solution that gets everything working. Add the following to your .zshrc:

# ------ Homebrew ZSH functions (for just + others)
# This will bring autocomplete for brew installed functions (exa, just, k6, etc)
# These will overwrite the oh-my-zsh plugins that conflict (like `git`)
# https://github.com/casey/just#shell-completion-scripts

# Init Homebrew, which adds environment variables
eval "$(brew shellenv)"

remove_conflicting_git_completions() {
    local git_completion_bash="$HOMEBREW_PREFIX/share/zsh/site-functions/git-completion.bash"
    local git_completion_zsh="$HOMEBREW_PREFIX/share/zsh/site-functions/_git"

    [ -e "$git_completion_bash" ] && rm "$git_completion_bash"
    [ -e "$git_completion_zsh" ] && rm "$git_completion_zsh"
}

# Delete the brew version of `git` completions because the built in ZSH
# ones are objectively better (and work with aliases)
# The reason this runs every time is because brew re-adds these files
# on `brew upgrade` (and other events)
remove_conflicting_git_completions

# Add Homebrew's site functions to fpath (minus git, because that causes conflicts)
# https://github.com/orgs/Homebrew/discussions/2797
# https://github.com/ohmyzsh/ohmyzsh/issues/8037
# https://github.com/ohmyzsh/ohmyzsh/issues/7062
fpath=($HOMEBREW_PREFIX/share/zsh/site-functions $fpath)

# Needed for autosuggestions (does compinit)
source $ZSH/oh-my-zsh.sh

If you want to read more about what else is worse about brew's git functions (or other solutions that can work), check these links:

Martel answered 7/1 at 21:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.