]> git.madduck.net Git - etc/pass.git/commitdiff

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 master
authormartin f. krafft <madduck@madduck.net>
Fri, 8 Dec 2023 13:06:38 +0000 (14:06 +0100)
committermartin f. krafft <madduck@madduck.net>
Fri, 8 Dec 2023 13:06:38 +0000 (14:06 +0100)
.bin/genpw-editor
.bin/pass [new file with mode: 0755]
.gitignore.d/pass
.zsh/aliases/genpw
.zsh/aliases/pmnpw

index adf8b661d7719852f3ad1aaa4edad29e3b9bd207..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 "$@"
diff --git a/.bin/pass b/.bin/pass
new file mode 100755 (executable)
index 0000000..c15a218
--- /dev/null
+++ b/.bin/pass
@@ -0,0 +1,31 @@
+#!/bin/sh
+set -eu
+
+real_pass() {
+  local OLDIFS; OLDIFS="$IFS"
+  IFS=:
+  local SELF; SELF="$(realpath $0)"
+  local CMD; CMD="$(basename "$SELF")"
+  local ret; ret=127
+  for p in $PATH; do
+    case "$SELF" in ($p/*) continue;; esac
+    if [ -x "$p/$CMD" ]; then
+      ${exec:-} "$p/$CMD" "$@"
+      ret=$?
+      break
+    fi
+  done
+  IFS="$OLDIFS"
+  return $ret
+}
+
+KEYGRIP=083F1106EEDD459ED7761C825FDB3E60FA7D8F3F
+
+gpg-connect-agent "keyinfo $KEYGRIP" /bye | while read a b c d e f g h; do
+  if [ "$g" != 1 ]; then
+    real_pass .meta/pass-key | /usr/lib/gnupg/gpg-preset-passphrase -c $KEYGRIP
+  fi
+  break
+done
+
+exec=exec real_pass "$@"
index 61a21a140e08853ebe8190285850e0c3fe80f197..6d0a4686d27f057b97660e55045b04438e051b94 100644 (file)
@@ -1,5 +1,6 @@
 *
 !/.bin/genpw-editor
+!/.bin/pass
 !/.gitignore.d/pass
 !/.zsh/aliases/genpw
 !/.zsh/aliases/getpw
index c49760298902e3178f600757d311dc623b60f3bb..8e11b078a5dcae9cf1358c559ba1c884eb9fbfc1 100644 (file)
@@ -1 +1,2 @@
-() { EDITOR="genpw-editor $2" pass edit "$1"; }
+() { EDITOR="genpw-editor" pass edit "$1"; }
+compdef $0=pass
index 2ff7e1a61b6279ca818e015a9d1090623849f606..a6d22c4ecd2325f20f6658cc9822055bf5eada4d 100644 (file)
@@ -1 +1 @@
-() { case "$1" in (*@*) genpw ${1%%@*}/$1;; (*) genpw $1/${1}@pobox.madduck.net ${@:2};; esac }
+() { case "$1" in (*@*) genpw ${1%%@*}/$1;; (*) genpw $1/${1}@pobox.madduck.net;; esac }