Skip to content

Instantly share code, notes, and snippets.

@GeneralD
Created March 16, 2025 05:24
Show Gist options
  • Save GeneralD/193494b0a43e3c2c744b48e0bb93b376 to your computer and use it in GitHub Desktop.
Save GeneralD/193494b0a43e3c2c744b48e0bb93b376 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
# helper functions for https://github.com/Aloxaf/gencomp
clean-gencomp() {
for file in $GENCOMP_DIR/*; do
local cmd=$(basename $file | sed 's/^_//')
command -v $cmd &>/dev/null && continue
echo "Remove completion for $cmd? [y/N]"
read -q
[[ $REPLY == "y" ]] && rm $file
done
}
# gen is another way to generate and save completions.
# example: gen mise completion zsh (gen saves the plain stdout)
# example: gencomp rg (gencomp saves the evaluation of -h or --help)
gen() {
local script="$($@ 2>/dev/null)"
local name=$(echo $script | head -n 1 | awk '{ print $2 }')
! command -v $name &>/dev/null && echo "Failed to generate completion for '$@'" && return 1
local file=$GENCOMP_DIR/_$name
echo $script > $file
echo "Generated completion for $name at $file"
compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment