From: martin f. krafft Date: Fri, 8 Dec 2023 13:06:38 +0000 (+0100) Subject: much improved password generator X-Git-Url: https://git.madduck.net/etc/pass.git/commitdiff_plain much improved password generator --- diff --git a/.bin/genpw-editor b/.bin/genpw-editor index adf8b66..94fd07d 100755 --- a/.bin/genpw-editor +++ b/.bin/genpw-editor @@ -1,15 +1,32 @@ #!/bin/sh set -eu -if command -v diceware >/dev/null; then - PW_GENERATOR='diceware -s2' +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 - PW_GENERATOR='pwgen -y 20 1' + elif command -v pwgen >/dev/null; then + pwgen -sy 32 1 -else - PW_GENERATOR='dd if=/dev/random bs=256 count=1 | base64' + else + dd if=/dev/random bs=32 count=1 | base64 -fi + fi +} -exec vim -c 'set noshelltemp' -c "0read! $PW_GENERATOR" -c 2d -n "$@" +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 "$@"