]> git.madduck.net Git - etc/pass.git/blobdiff - .bin/genpw-editor

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

much improved password generator
[etc/pass.git] / .bin / genpw-editor
index 108f1b61d8f0ebf774b3ebfb3136c1bfb83d5d11..94fd07dd01645e382338a2d305186cc39d7ecc6b 100755 (executable)
@@ -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 "$@"