willpower232

willpower232 / passmenu.sh

Last active 1 month ago

Like 0

dmenu script for pass

Revision e075b9975037113aaeb445ae2e30b33328c2ee6b

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