-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitwarden-rofi
More file actions
executable file
·142 lines (123 loc) · 2.5 KB
/
bitwarden-rofi
File metadata and controls
executable file
·142 lines (123 loc) · 2.5 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
entries=()
message=''
function update_entries() {
SAVEIFS="$IFS" # Save current IFS
IFS=$'\n' # Change IFS to new line
entries="$(
rbw list --fields id,name,user,folder |
sed --regexp-extended 's/([^\t]+?)\t([^\t]+?)\t([^\t]+?)\t([^\t]+?)/\4\/\2\t[\3]\t[id: \1]\\0icon\\x1ffolder\\x1finfo\\x1f\1/' |
sed --regexp-extended 's|^/|(none)/|'
)"
entries=($entries)
IFS="$SAVEIFS" # Restore IFS
}
function display_rofi() {
for entry in "${entries[@]}"; do
echo -e "$entry"
done | rofi_config
}
function rofi_config() {
_message="Alt+a - Sync | Alt+t - type username + password | Alt+p - copy password | Alt+u - copy username | Alt+k - type code $message"
message=''
rofi \
-i \
-theme slate-slim \
-no-custom \
-location 1 \
-theme-str '
window {
font: "Noto Sans 10";
padding: 0;
width: 100%;
}
listview {
lines: 5;
}
inputbar {
children: [entry];
}
' \
-mesg "$_message" \
-p 'Bitwarden' \
-dmenu \
-kb-custom-19 'Alt+a' \
-kb-custom-11 'Alt+p' \
-kb-custom-12 'Alt+u' \
-kb-custom-13 'Alt+t' \
-kb-custom-14 'Alt+k' \
$@
}
function do-type() {
read -r data
echo "$data" | xargs xdotool type --clearmodifiers
}
function do-copy() {
read -r data
echo "$data" | xclip -sel clip
}
function handle_rofi_type() {
id="$1"
field="$2"
method="$3"
sleep 0.1
data=""
case "$field" in
"username")
data="$(rbw list --fields id,user | grep "^$id" | cut -f2)"
;;
"password")
data="$(rbw get "$id")"
;;
"code")
data="$(rbw code "$id")"
;;
esac
case "$method" in
"type")
echo "$data" | do-type
;;
"copy")
echo "$data" | do-copy
;;
esac
}
rbw unlock || exit 2
update_entries
while true; do
chosen="$(display_rofi)"
exit_code="$?"
chosen="$(echo "$chosen" | sed --regexp-extended "s|.*?\t\[id\: (.+?)\]$|\1|")"
case "$exit_code" in
0)
handle_rofi_type "$chosen" "password" "type"
exit
;;
20)
handle_rofi_type "$chosen" "password" "copy"
exit
;;
21)
handle_rofi_type "$chosen" "username" "copy"
exit
;;
22)
handle_rofi_type "$chosen" "username" "type"
xdotool key --clearmodifiers Tab;
handle_rofi_type "$chosen" "password" "type"
exit
;;
23)
handle_rofi_type "$chosen" "code" "type"
exit
;;
28)
rbw sync
update_entries
message="| Synced"
;;
*)
exit 1
;;
esac
done