willpower232

willpower232 / passmenu.sh

Last active 1 month ago

Like 0

dmenu script for pass

Revision b11e4b8a810f17c1db6f7f7f45c432755922c37b

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