#!/bin/sh set -eu generate_pw() { local pw if command -v diceware >/dev/null; then words=4 DICEWARE="$(diceware -n$words -d" " -s2 | sed -re "s,['\"],\\\\&,g")" \ python3 - <<-_eof import os, random, string, shlex words = shlex.split(os.getenv('DICEWARE')) delims = random.choices(string.digits, k=${words}-1) for w, d in zip(words[:-1], delims[:len(words)-1]): print(w, end=d) print(words[-1]) _eof elif command -v pwgen >/dev/null; then pwgen -sy 32 1 else dd if=/dev/random bs=32 count=1 | base64 fi } PASSPW="$(generate_pw)" X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}" echo -n "$PASSPW" | xclip -selection $X_SELECTION export PASSWD_ESCAPED="$(echo $PASSPW | sed -e 's,",\\",g')" exec vim -c 'set noshelltemp' -c '0read! echo -n "$PASSWD_ESCAPED"' -c 2d -n "$@"