90 lines
2.5 KiB
Bash
90 lines
2.5 KiB
Bash
#!/bin/zsh
|
|
# Completion registration file
|
|
# This file handles all completion registrations
|
|
|
|
# Load custom completion files
|
|
for completion_file in ~/.local/share/zsh/*-autocomplete.zsh(N); do
|
|
if [ -f "$completion_file" ]; then
|
|
source "$completion_file"
|
|
fi
|
|
done
|
|
|
|
# Lazy loading function for completions
|
|
_lazy_load_completion() {
|
|
local cmd="$1"
|
|
local completion_cmd="$2"
|
|
|
|
eval "${cmd}() {
|
|
unfunction $cmd
|
|
eval \"\$($completion_cmd)\"
|
|
$cmd \"\$@\"
|
|
}"
|
|
}
|
|
|
|
# Load lightweight completions immediately
|
|
if command -v eza &> /dev/null; then compdef eza=ls; fi
|
|
|
|
# Defer heavy completions with lazy loading
|
|
if command -v kubefwd &> /dev/null; then _lazy_load_completion kubefwd "kubefwd completion zsh"; fi
|
|
if command -v bombadil &> /dev/null; then _lazy_load_completion bombadil "bombadil generate-completions zsh"; fi
|
|
|
|
# Load remaining completions normally (they're lightweight)
|
|
if command -v rop &> /dev/null; then eval "$(rop completion zsh)"; fi
|
|
if command -v goq &> /dev/null; then eval "$(goq completion zsh)"; fi
|
|
if command -v drop &> /dev/null; then eval "$(drop completion zsh)"; fi
|
|
|
|
# Custom completion for kf function using kubectx contexts
|
|
_kf_completion() {
|
|
local -a contexts
|
|
# Get all contexts and extract unique cluster names (remove -read and -security suffixes)
|
|
contexts=($(kubectx 2>/dev/null | sed 's/-read$//; s/-security$//' | sort -u))
|
|
|
|
if [[ ${#contexts[@]} -gt 0 ]]; then
|
|
_values 'cluster' "${contexts[@]}"
|
|
fi
|
|
}
|
|
|
|
# Register the completion
|
|
compdef _kf_completion kf
|
|
|
|
|
|
_yay_completion() {
|
|
local cur prev opts
|
|
COMPREPLY=()
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
opts="-Syyu -Syu -Ss -S -R -Q -Si -Sc help install remove list clean"
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
|
return 0
|
|
}
|
|
|
|
# For zsh:
|
|
_yay_zsh_completion() {
|
|
local -a opts
|
|
opts=(
|
|
'-Syyu:Update system'
|
|
'-Syu:Update system'
|
|
'-Ss:Search packages'
|
|
'-S:Install system-wide'
|
|
'-R:Remove package'
|
|
'-Q:List installed'
|
|
'-Si:Package info'
|
|
'-Sc:Clean cache'
|
|
'help:Show help'
|
|
'install:Install to user env'
|
|
'remove:Remove from user env'
|
|
'list:List installed packages'
|
|
'clean:Clean nix store'
|
|
)
|
|
_describe 'yay commands' opts
|
|
}
|
|
|
|
# Enable completion based on shell
|
|
if [[ -n "${BASH_VERSION:-}" ]]; then
|
|
complete -F _yay_completion yay
|
|
elif [[ -n "${ZSH_VERSION:-}" ]]; then
|
|
compdef _yay_zsh_completion yay
|
|
fi
|
|
|