mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-11-24 01:13:03 +01:00
feat(bitwarden): add completions for bw and bws (#14261)
* feat(bws): add completion plugin * feat(bitwarden): unify bw and bws completions
This commit is contained in:
1 parent
87aa1a9b89
commit
e35c9b4b67
2 files changed
+61
No files matched your search
@@ -0,0 +1,16 @@
|
||||
# Bitwarden plugin
|
||||
|
||||
This plugin adds Zsh completions for whichever Bitwarden CLIs are installed:
|
||||
|
||||
- [Bitwarden CLI (`bw`)](https://bitwarden.com/help/cli/)
|
||||
- [Bitwarden Secrets Manager CLI (`bws`)](https://bitwarden.com/help/secrets-manager-cli/)
|
||||
|
||||
To enable it, add `bitwarden` to the plugins array in your `.zshrc`:
|
||||
|
||||
```zsh
|
||||
plugins=(... bitwarden)
|
||||
```
|
||||
|
||||
Each installed CLI generates and refreshes its own completion cache in the
|
||||
background when the plugin loads. The cache files are
|
||||
`$ZSH_CACHE_DIR/completions/_bw` and `$ZSH_CACHE_DIR/completions/_bws`.
|
||||
@@ -0,0 +1,45 @@
|
||||
# Autocompletion for the Bitwarden CLI (bw) and Secrets Manager CLI (bws).
|
||||
() {
|
||||
local cli completion cache_file
|
||||
local -a generator_args
|
||||
for cli in bw bws; do
|
||||
completion="_$cli"
|
||||
cache_file="$ZSH_CACHE_DIR/completions/$completion"
|
||||
|
||||
if (( ! $+commands[$cli] )); then
|
||||
# compinit can register a cached completion after the CLI is removed.
|
||||
if [[ -f "$cache_file" && ${_comps[$cli]-} == "$completion" ]]; then
|
||||
unset "_comps[$cli]"
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
|
||||
case "$cli" in
|
||||
bw)
|
||||
generator_args=(completion --shell zsh)
|
||||
# bw emits function definitions. Use ksh-style autoload to run _bw
|
||||
# on the first Tab press as well as loading its helper functions.
|
||||
autoload -Uk "$completion"
|
||||
;;
|
||||
bws)
|
||||
generator_args=(completions zsh)
|
||||
autoload -Uz "$completion"
|
||||
;;
|
||||
esac
|
||||
# Register the completion if compinit hasn't picked it up yet.
|
||||
if [[ -z ${_comps[$cli]-} ]]; then
|
||||
_comps[$cli]=$completion
|
||||
fi
|
||||
|
||||
() {
|
||||
zmodload -F zsh/files b:zf_mv || return
|
||||
local temp_file
|
||||
temp_file=$(mktemp "${cache_file:h}/.$completion.XXXXXXXX") || return
|
||||
if command "$cli" "$@" >| "$temp_file" && [[ -s "$temp_file" ]] &&
|
||||
zf_mv -f -- "$temp_file" "$cache_file"; then
|
||||
return
|
||||
fi
|
||||
rm -f -- "$temp_file"
|
||||
} "${generator_args[@]}" &|
|
||||
done
|
||||
}
|
||||
Reference in new issue
Block a user