Skip to content

Instantly share code, notes, and snippets.

@mdeous mdeous/multipass.zsh
Last active Oct 22, 2019

Embed
What would you like to do?
multipass.zsh - A wrapper for people using multiple pass (password-store) stores
#
# multipass.zsh
#
# A wrapper to pass (password-store) for managing multiple
# store paths with a single command while still benefiting
# from Zsh's completion features.
#
# Usage: add the following lines to your .zshrc:
# source /path/to/multipass.zsh
# PASSWORD_STORES[pass1]=/path/to/pass1-store
# PASSWORD_STORES[pass2]=/path/to/pass2-store
#
# You can now type "multipass pass1 <tab>" and get completion
# for this specific store.
#
typeset -A PASSWORD_STORES
PASSWORD_STORES=()
multipass() {
local store_path
if [ $# -lt 1 ]; then
echo 'Usage: multipass PASS_NAME [PASS_ARGS...]'
return
fi
if [[ "${(k)PASSWORD_STORES[$1]}" == "$1" ]]; then
store_path="${PASSWORD_STORES[$1]}"
shift
PASSWORD_STORE_DIR="${store_path}" pass $@
else
echo "No '$1' store found (available: '${(kj:,:)PASSWORD_STORES}')"
fi
}
_multipass() {
local -a options=()
local store_name="${(k)PASSWORD_STORES[${words[2]}]}"
if [[ "${words[2]}" != "${store_name}" ]] || [[ "${words[2]}" == "" ]]; then
for passname in ${(k)PASSWORD_STORES}; do
options+=$passname
done
_describe 'values' options
else
PASSWORD_STORE_DIR="${PASSWORD_STORES[${words[2]}]}" _pass
fi
}
compdef _multipass multipass
@mdeous

This comment has been minimized.

Copy link
Owner Author

mdeous commented Oct 9, 2017

Usage

Add these lines to your .zshrc :

source /path/to/multipass.zsh
PASSWORD_STORES[pass1]=/path/to/pass1-store
PASSWORD_STORES[pass2]=/path/to/pass2-store

After re-sourcing your .zshrc to apply the changes, you can now query any pass store with :

$ multipass pass1 [args...]

Completion is provided for store names...

 $ multipass <tab>

... and for pass entries!

$ multipass pass1 <tab>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.