Skip to content

Instantly share code, notes, and snippets.

@mdeous
Last active July 28, 2021 17:12
Show Gist options
  • Save mdeous/ed618ee28c4940faf403d42c995a096b to your computer and use it in GitHub Desktop.
Save mdeous/ed618ee28c4940faf403d42c995a096b to your computer and use it in GitHub Desktop.
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
Copy link
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>

@Loki-Afro
Copy link

Loki-Afro commented May 13, 2020

@mdeous thanks a lot, thanks to you i can finally throw the ring into the damn vulcan :D

meme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment