]> git.madduck.net Git - etc/pass.git/blob - .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
1 #!/bin/sh
2 set -eu
3
4 generate_pw()
5 {
6   local pw
7   if command -v diceware >/dev/null; then
8     words=4
9     DICEWARE="$(diceware -n$words -d" " -s2 | sed -re "s,['\"],\\\\&,g")" \
10     python3 - <<-_eof
11         import os, random, string, shlex
12         words = shlex.split(os.getenv('DICEWARE'))
13         delims = random.choices(string.digits, k=${words}-1)
14         for w, d in zip(words[:-1], delims[:len(words)-1]):
15           print(w, end=d)
16         print(words[-1])
17         _eof
18
19   elif command -v pwgen >/dev/null; then
20     pwgen -sy 32 1
21
22   else
23     dd if=/dev/random bs=32 count=1 | base64
24
25   fi
26 }
27
28 PASSPW="$(generate_pw)"
29 X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
30 echo -n "$PASSPW" | xclip -selection $X_SELECTION
31 export PASSWD_ESCAPED="$(echo $PASSPW | sed -e 's,",\\",g')"
32 exec vim -c 'set noshelltemp' -c '0read! echo -n "$PASSWD_ESCAPED"' -c 2d -n "$@"