diff --git a/plugins/fizzy/README.md b/plugins/fizzy/README.md new file mode 100644 index 000000000..cb19b1a97 --- /dev/null +++ b/plugins/fizzy/README.md @@ -0,0 +1,18 @@ +# Fizzy CLI plugin + +This plugin adds completion for the [Fizzy CLI (fizzy)](https://github.com/basecamp/fizzy-cli). + +To use it, add `fizzy` to the plugins array in your zshrc file: + +```zsh +plugins=(... fizzy) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and automatically updates it when the +plugin is loaded, which is usually when you start a new terminal emulator. + +The cache is stored at `$ZSH_CACHE_DIR/completions/_fizzy`. diff --git a/plugins/fizzy/fizzy.plugin.zsh b/plugins/fizzy/fizzy.plugin.zsh new file mode 100644 index 000000000..9dd50ab25 --- /dev/null +++ b/plugins/fizzy/fizzy.plugin.zsh @@ -0,0 +1,24 @@ +# Autocompletion for the Fizzy CLI (fizzy). +if (( ! $+commands[fizzy] )); then + return +fi + +# If the completion isn't registered yet, autoload it and bind it to `fizzy`. +# Otherwise, compinit will have already done that from the cache. +if [[ -z ${_comps[fizzy]-} ]]; then + typeset -g -A _comps + autoload -Uz _fizzy + _comps[fizzy]=_fizzy +fi + +zmodload -F zsh/files b:zf_mv || return +() { + local cache_file="$ZSH_CACHE_DIR/completions/_fizzy" + local temp_file + temp_file=$(mktemp "$ZSH_CACHE_DIR/completions/._fizzy.XXXXXXXX") || return + if command fizzy completion zsh >| "$temp_file" && [[ -s "$temp_file" ]] && + zf_mv -f -- "$temp_file" "$cache_file"; then + return + fi + rm -f -- "$temp_file" +} &|