# Setup shell completions for Bash and Zsh # Named with 'zz-' prefix to guarantee late execution after all PATH and tool # additions in ~/.rc.d/*.sh have completed. _setup_completions() { # Only initialize completions for interactive shells case $- in *i*) ;; *) return 0 ;; esac # ------------------------------------------------------------------------- # ZSH Autocompletion Setup # ------------------------------------------------------------------------- if [ -n "$ZSH_VERSION" ]; then # Candidate completion directories for _dir in \ "/opt/homebrew/share/zsh-completions" \ "/usr/local/share/zsh-completions" \ "/usr/share/zsh-completions" \ "/opt/homebrew/share/zsh/site-functions" \ "/usr/local/share/zsh/site-functions" \ "$HOME/.zsh_functions" do if [ -d "$_dir" ]; then case " ${fpath[*]} " in *" $_dir "*) ;; *) fpath=("$_dir" "${fpath[@]}") ;; esac fi done # If you receive "zsh compinit: insecure directories" warnings, run: # chmod go-w '/opt/homebrew/share' # chmod -R go-w '/opt/homebrew/share/zsh' # Initialize compinit with 24-hour cache check for fast startup (~2ms) autoload -Uz compinit _zcompdump="${ZDOTDIR:-$HOME}/.zcompdump" if [ -n "$(find "$_zcompdump" -mtime -1 2>/dev/null)" ]; then compinit -C -d "$_zcompdump" else compinit -d "$_zcompdump" fi unset _zcompdump _dir # ------------------------------------------------------------------------- # Bash Autocompletion Setup # ------------------------------------------------------------------------- elif [ -n "$BASH_VERSION" ]; then if ! shopt -oq posix; then for _comp in \ "/opt/homebrew/etc/profile.d/bash_completion.sh" \ "/usr/local/etc/profile.d/bash_completion.sh" \ "/usr/share/bash-completion/bash_completion" \ "/etc/bash_completion" \ "$HOME/.local/share/bash-completion/bash_completion" do if [ -r "$_comp" ]; then \. "$_comp" break fi done unset _comp fi fi } _setup_completions unset -f _setup_completions