]> 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:

add getlogin function master
authormartin f. krafft <madduck@madduck.net>
Thu, 24 Apr 2025 09:12:38 +0000 (11:12 +0200)
committermartin f. krafft <madduck@madduck.net>
Thu, 24 Apr 2025 09:12:38 +0000 (11:12 +0200)
.gitignore.d/pass
.zsh/zshrc/parts.d/50-pass [new file with mode: 0644]

index 6d0a4686d27f057b97660e55045b04438e051b94..9480707e4ec30e5f049ecc8f2ed0b2af8c826d79 100644 (file)
@@ -5,3 +5,4 @@
 !/.zsh/aliases/genpw
 !/.zsh/aliases/getpw
 !/.zsh/aliases/pmnpw
+!/.zsh/zshrc/parts.d/50-pass
diff --git a/.zsh/zshrc/parts.d/50-pass b/.zsh/zshrc/parts.d/50-pass
new file mode 100644 (file)
index 0000000..da55c20
--- /dev/null
@@ -0,0 +1,36 @@
+getlogin() { 
+  local pw uid
+  parse_pass_output() {
+    local key rest pw
+    while read key rest; do
+      if [ -z "$pw" ]; then
+        pw="$key"
+        echo "pw=$pw"
+        continue
+      fi
+
+      if [ -z "$uid" ] && [ -n "$rest" ]; then
+        case "${key%:}" in
+          login|user|username|id|userid) echo uid="$rest"; break;;
+        esac
+      fi
+    done
+  }
+
+  eval $(pass "$1" | parse_pass_output)
+
+  [ -n "$uid" ] || uid="${1##*/}"
+
+  xclip_() {
+    # -quiet is not: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1103990
+    xclip -rmlastnl -loops 1 -selection clipboard -quiet 2>/dev/null
+  }
+
+  echo >&2 "Go paste the UID: $uid"
+  echo "$uid" | xclip_
+  echo >&2 "Now go paste the password"
+  echo "$pw" | xclip_
+}
+compdef getlogin=pass
+
+# vim:ft=zsh