#!/usr/bin/env bash ## Copy a password using the password manager `pass` and visit the associated ## website using the URL in the password's file. The username is appended to the ## URL as a fragment in case it needs to be cut and pasted. ## ## Usage: pass-use ## ## Dependencies: fzf, GNU coreutils, GNU sed, pass, ripgrep, xdg-utils set -euo pipefail shopt -s inherit_errexit die() { echo -e "$(basename "$0"): $1" >&2; exit 1; } [[ " $* " =~ ' --help ' ]] && sed -n 's/^## *//p' "$0" && exit # Get password name. cd "${PASSWORD_STORE_DIR-~/.password-store}" password_name=$(fzf | sed 's/\.gpg$//') # Copy password. pass show -c "$password_name" # Visit website. file_text=$(pass show "$password_name") url=$(rg -r '$1' '^URL: (.*)' <<< "$file_text") || die 'URL not found' url+=#$(sed -n 's/^Username: //p' <<< "$file_text") browser=$(rg -r '$1' '^Browser: (.*)' <<< "$file_text" || echo xdg-open) type "${browser/ *}" &> /dev/null || die "web browser not found: $browser" $browser "$url" &> /dev/null &