Skip to content

Instantly share code, notes, and snippets.

@sushichan044
Created January 6, 2026 05:02
Show Gist options
  • Select an option

  • Save sushichan044/0c5bfb1586fc190abcdb9b88f93e4ee8 to your computer and use it in GitHub Desktop.

Select an option

Save sushichan044/0c5bfb1586fc190abcdb9b88f93e4ee8 to your computer and use it in GitHub Desktop.
# Inspired by: https://github.com/elecdeer/dotfiles/blob/14604501ed14095f30ba9d0240b6dc0f50a6dc90/hanger/plugins/on-demand-completion/on-demand-completion.plugin.zsh
#
# usage: lazy_completion <command_name> [completion_command]
# Example:
# lazy_completion 'gh' 'gh completion -s zsh'
lazy_completion() {
local cmd_name=$1
local completion_command="$2"
local function_name="_${cmd_name}"
if ! command -v "$cmd_name" &>/dev/null; then
return
fi
eval "function $function_name() {
unfunction '$function_name'
eval \"\$(eval $completion_command)\"
\$_comps[$cmd_name]
}"
compdef $function_name $cmd_name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment