iTranslated by AI
How to Enable Git Tab Completion on Mac
Overview
I am sharing how to enable Git tab completion on Mac as a memo.
Execution Environment
- Apple M1 Pro
- zsh
Steps
1. Check if Homebrew is installed
brew --version
If the version is displayed, you're good to go.
If it's not installed, please install it from the official website.
2. Install zsh-completions
brew install zsh-completions
It will be installed in /opt/homebrew/share/zsh-completions.
3. Add settings to .zshrc
vi ~/.zshrc
Open .zshrc.
# Add zsh-completions to fpath
fpath=("/opt/homebrew/share/zsh-completions" $fpath)
# Load compinit
autoload -Uz compinit
compinit
Add the above to the end of the file.
autoload : Registers as a function that can be lazy-loaded (a command to make zsh functions callable as commands)
compinit : A function that enables the Tab completion feature itself (loads completion functions from fpath)
-U : Setting to ignore pre-existing aliases when loading functions
-z : Explicitly indicates that it is a function for Zsh (ceremonial)
4. Apply the settings
source ~/.zshrc
This completes the setup.
When asked for confirmation
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?
zsh compinit: Insecure directories found. Run compaudit for a list.
Do you want to ignore insecure directories and continue [y] or abort compinit [n]?
It seems this confirmation appears when the permissions for the directory where zsh-completions is installed are too broad.
You can ignore it and continue, but it is better to change the permissions with chmod.
sudo chmod -R go-w /opt/homebrew/share
-R : Recursively changes the permissions of the directories and files under that folder.
go-w : Removes write permission (-w) from g = group and o = others.
By the way, you can see which directories are insecure using the compaudit command.
compaudit
Example
There are insecure directories:
/opt/homebrew/share
Discussion