Skip to content

Instantly share code, notes, and snippets.

@whi-tw
Last active February 11, 2022 17:40
Show Gist options
  • Save whi-tw/e1ede8654707b1203d78c4e9d663f803 to your computer and use it in GitHub Desktop.
Save whi-tw/e1ede8654707b1203d78c4e9d663f803 to your computer and use it in GitHub Desktop.
zsh plugin to add gh command completion
# TODO: 2021-12-28: remove this bit of code as it exists in oh-my-zsh.sh
# Add completions folder in $ZSH_CACHE_DIR
command mkdir -p "$ZSH_CACHE_DIR/completions"
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
# If the completion file does not exist, generate it and then source it
# Otherwise, source it and regenerate in the background
if [[ ! -f "$ZSH_CACHE_DIR/completions/_gh" ]]; then
gh completion -s zsh >| "$ZSH_CACHE_DIR/completions/_gh"
source "$ZSH_CACHE_DIR/completions/_gh"
else
source "$ZSH_CACHE_DIR/completions/_gh"
gh completion -s zsh >| "$ZSH_CACHE_DIR/completions/_gh" &|
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment