Last active
July 28, 2021 17:12
-
-
Save mdeous/ed618ee28c4940faf403d42c995a096b to your computer and use it in GitHub Desktop.
multipass.zsh - A wrapper for people using multiple pass (password-store) stores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 anypass
store with :Completion is provided for store names...
... and for
pass
entries!