willpower232

willpower232 / passmenu.sh

Last active 1 month ago

Like 0

dmenu script for pass

Revision 2cb34a4e344c35a1c0b2cb976a5324394e0b4847

passmenu.sh Raw
1#!/usr/bin/env bash
2
3# 1 - source copy from https://geluk.io/p/passmenu.sh (https://github.com/Baggykiin/pass-winmenu)
4# 2 - make dmenu case insensitive
5# 3 - correct include_username variable
6
7shopt -s nullglob globstar
8
9typeit=0
10include_username=1
11editit=0
12
13while [[ -n "$1" ]]; do
14 if [[ $1 == "--type" ]]; then
15 typeit=1
16 elif [[ $1 == "--no-username" ]]; then
17 include_username=0
18 elif [[ $1 == "--edit" ]]; then
19 editit=1
20 elif [[ $1 == "--" ]]; then
21 break;
22 fi
23 shift
24done
25
26
27prefix=${PASSWORD_STORE_DIR-~/.password-store}
28password_files=( "$prefix"/**/*.gpg )
29password_files=( "${password_files[@]#"$prefix"/}" )
30password_files=( "${password_files[@]%.gpg}" )
31
32password=$(printf '%s\n' "${password_files[@]}" | dmenu -i "$@")
33
34if [[ $editit -eq 1 ]]; then
35 # Insert the edit command for your preferred terminal here:
36 #termite -e "pass edit '$password' > /dev/null"
37 #xterm "pass edit '$password' > /dev/null"
38 #urxvt -e "pass edit '$password' > /dev/null"
39 #gnome-terminal -- pass edit "$password" > /dev/null
40 # ..etc
41 exit
42fi
43
44[[ -n $password ]] || exit
45
46if [[ $typeit -eq 0 ]]; then
47 pass show -c "$password" | xclip
48
49else
50 pwfile=$(pass show "$password")
51 password=$(printf "%s" "$pwfile" | sed -n 1p)
52 username=$(printf "%s" "$pwfile" | grep -Po "[Uu]ser(name)?: \K(.*)")
53 printf '%s' "$password" | xclip -selection clipboard
54 print '%s' "$password" | xclip
55 if [ -z "$username" ] || [[ $include_username -eq 0 ]]; then
56 printf '%s' "$password" | xdotool type --clearmodifiers --file -
57 else
58 pstr=$(printf '%s\t%s' "$username" "$password")
59 xdotool type "$pstr"
60 fi
61fi
62