summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2016-02-28 22:06:25 +0100
committerYves Fischer <yvesf-git@xapek.org>2016-02-28 22:06:25 +0100
commit7b9a197cd1197ab1df930a05dcf19f82ff080f4a (patch)
treed4fb6bd7a0d1a5780bc15b1062c6e7a725fefea2 /packages
parenta307e0474e78c51590aeac95dbc5587a87ef6501 (diff)
downloaddebian-packages-7b9a197cd1197ab1df930a05dcf19f82ff080f4a.tar.gz
debian-packages-7b9a197cd1197ab1df930a05dcf19f82ff080f4a.zip
add dmenu-pass
Diffstat (limited to 'packages')
-rwxr-xr-xpackages/scripts/resources/bin/dmenu-pass79
-rwxr-xr-xpackages/scripts/resources/bin/dmenu-pass.sh40
2 files changed, 79 insertions, 40 deletions
diff --git a/packages/scripts/resources/bin/dmenu-pass b/packages/scripts/resources/bin/dmenu-pass
new file mode 100755
index 0000000..c1d1914
--- /dev/null
+++ b/packages/scripts/resources/bin/dmenu-pass
@@ -0,0 +1,79 @@
+#!/usr/bin/env bash
+
+shopt -s nullglob globstar
+prefix=${PASSWORD_STORE_DIR-~/.password-store}
+password_files=( "$prefix"/**/*.gpg )
+password_files=( "${password_files[@]#"$prefix"/}" )
+password_files=( "${password_files[@]%.gpg}" )
+
+notify() {
+ # prints an integer which is the notification id
+ # :param 1: the application name
+ # :param 2: summary
+ # sadly this is required until there is a direct way to call Notify
+ python -c "import dbus; print(dbus.Bus().call_blocking(
+ 'org.freedesktop.Notifications', '/org/freedesktop/Notifications',
+ 'org.freedesktop.Notifications', 'Notify', 'susssasa{sv}i',
+ ('$1', # app_name
+ 0, # replaces_id
+ '', # app_icon
+ '$2', # summary
+ 'body', # body
+ [], # actions
+ {}, # hints
+ 0 # expire_timeout
+ )))"
+}
+
+notify_close() {
+ # :param 1: close the notification with this id
+ dbus-send --type=method_call --dest='org.freedesktop.Notifications' \
+ /org/freedesktop/Notifications org.freedesktop.Notifications.CloseNotification \
+ "uint32:$1"
+}
+
+dmenu_show() {
+ # :param 1: Name of the password (`pass' path)
+ echo "Done"
+ pass show "$1" 2>&1 | \
+ sed -e 's/^\(pass\|password\):.*/\1: XXXX/' | # mask password \
+ sed -n -e '/^.\+$/p' # delete empty lines
+}
+
+write_clipboard() {
+ # blocks until paste action happens
+ xclip -i -verbose -l 1 2>/dev/null
+}
+
+
+password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
+
+if [ -z "$password" ]; then
+ exit
+fi
+
+while true; do
+ choice=$(dmenu_show "$password" | dmenu -l 3 -p "Clipboard $pass")
+ case "$choice" in
+ login:*|user:*|username:*)
+ id=$(notify "dmenu-pass" "Ready to paste username")
+ pass show "$password" 2>&1 \
+ | sed -ne 's/^\(login\|user\|username\): \?\(.*\)/\2/p' \
+ | write_clipboard
+ notify_close $id
+ ;;
+ pass:*|password:*)
+ id=$(notify "dmenu-pass" "Ready to paste password")
+ pass show "$password" 2>&1 \
+ | sed -ne 's/^\(pass\|password\): \?\(.*\)/\2/p' \
+ | write_clipboard
+ notify_close $id
+ ;;
+ Done|"")
+ break
+ ;;
+ *)
+ echo $choice
+ ;;
+ esac
+done
diff --git a/packages/scripts/resources/bin/dmenu-pass.sh b/packages/scripts/resources/bin/dmenu-pass.sh
deleted file mode 100755
index bb3be7a..0000000
--- a/packages/scripts/resources/bin/dmenu-pass.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/env bash
-
-shopt -s nullglob globstar
-
-prefix=${PASSWORD_STORE_DIR-~/.password-store}
-password_files=( "$prefix"/**/*.gpg )
-password_files=( "${password_files[@]#"$prefix"/}" )
-password_files=( "${password_files[@]%.gpg}" )
-
-password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
-
-[[ -n $password ]] || exit
-
-while true; do
- pass show "$password" 2>&1 \
- | sed -e 's/^pass:.*/pass: XXXX/' \
- | xmessage -file - \
- -buttons "Done:1,Copy 'login':2,Copy 'pass':3,Copy all:4" \
- -default "Done" \
- -nearmouse -timeout 10
- case "$?" in
- 2)
- pass show "$password" 2>&1 \
- | sed -ne 's/^login: \(.*\)/\1/p' \
- | xclip -i -verbose -l 1 2>/dev/null
- ;;
- 3)
- pass show "$password" 2>&1 \
- | sed -ne 's/^pass: \(.*\)/\1/p' \
- | xclip -i -verbose -l 1 2>/dev/null
- ;;
- 4)
- pass show "$password" 2>&1 \
- | xclip -i -verbose -l 1 2>/dev/null
- ;;
- *)
- break
- ;;
- esac
-done