-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfzf-pass
executable file
·120 lines (102 loc) · 2.92 KB
/
fzf-pass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
# This script is the result of forking rofi-pass (https://github.com/carnager/rofi-pass),
# replacing Rofi with fzf, and removing everything that I personally don't need.
listPasswords() {
find -L ~/passwords -name '*.gpg' -printf '%P\n' | sed 's/.gpg$//' | sort
}
generateOtp() {
declare -A stuff
readPassFile
pass otp "$selected_password"
}
readarray -t fzf_output < <(
listPasswords 2>/dev/null |
fzf --prompt='~/passwords/' \
--color='dark,hl:blue:regular,fg+:white:regular,hl+:blue:regular:reverse,query:white:regular,info:gray:regular,prompt:blue:regular,pointer:blue:bold' \
--expect='tab,[,{,],},\')
(( ${#fzf_output[@]} == 2 )) || exit
key=${fzf_output[0]}
selected_password=${fzf_output[1]}
[[ $selected_password ]] || exit
readPassFile() {
readarray -t lines < <(pass show "$selected_password")
password=${lines[0]}
stuff[pass]=$password
while read -r line; do
unset _id _val
case $line in
otpauth://*)
_id=OTP
_val=
;;
*)
_id=${line%%: *}
_val=${line#* }
;;
esac
if [[ -n $_id ]]; then
stuff[${_id}]=$_val
fi
done < <(printf '%s\n' "${lines[@]:1}" | awk '$1 ~ /:$/ || /otpauth:\/\// {$1=$1;print}')
if [[ -z ${stuff[autotype]} ]]; then
stuff[autotype]='login :tab pass'
fi
if [[ -z ${stuff[login]} ]]; then
stuff[login]=meribold
fi
}
case $key in
'')
output=$(pass show "$selected_password")
num_lines=$(wc -l <<< "$output")
max_line_length=$(wc -L <<< "$output")
i3-msg -q "resize set $((max_line_length > 36 ? max_line_length * 13 : 468)) $((num_lines > 4 ? num_lines * 27 : 108)); move position center"
tput civis
printf '%s' "$output"
read -rn1
exit
;;
tab)
$BROWSER "$(pass show "$selected_password" | grep 'url: ' | gawk '{sub(/:/,"")}{print $2}1' | head -1)"
exit
;;
esac
x_repeat_enabled=$(xset q | awk '/auto repeat:/ {print $3}')
cleanup() {
xset r "$x_repeat_enabled"
}
trap cleanup EXIT
xset r off
declare -A stuff
readPassFile
trap '' SIGHUP
case $key in
\[)
sleep 0.05
xdotool type --clearmodifiers "${stuff[login]}"
;;
\{)
echo -n "${stuff[login]}" | xsel -b
;;
\])
sleep 0.05
xdotool type --clearmodifiers -- "$password"
;;
\})
echo -n "$password" | xsel -b -t 10000
;;
\\)
sleep 0.05
for word in ${stuff[autotype]}; do
case $word in
:tab) xdotool key Tab;;
:space) xdotool key space;;
:delay) sleep 2;;
:enter) xdotool key Return;;
:otp) xdotool type --clearmodifiers "$(generateOtp)";;
pass) xdotool type --clearmodifiers -- "$password";;
*) printf '%s' "${stuff[${word}]}" | xdotool type --clearmodifiers --file -;;
esac
done
;;
esac &