#!/usr/bin/env bash ## Generate a password using the password manager `pass` and then open the ## password's file in the default text editor. ## ## Usage: pass-generate [...] [] ## ## Dependencies: GNU coreutils, GNU findutils, GNU sed, pass set -euo pipefail shopt -s inherit_errexit die() { echo "$(basename "$0"): $1" >&2; exit 1; } [[ " $* " =~ ' --help ' ]] && sed -n 's/^## \?//p' "$0" && exit (( $# >= 1 )) || die 'missing argument' pass generate -c "$@" dir=${PASSWORD_STORE_DIR:-~/.password-store} password_name=$(find "$dir"/* -mmin -0.05 | xargs basename -s .gpg) # Don't run `pass edit` in a pipeline (using xargs) because doing so will result # in a GnuPG error if the private key hasn't already been decrypted. pass edit "$password_name"