-
Notifications
You must be signed in to change notification settings - Fork 1
/
rofi-lpass
executable file
·90 lines (75 loc) · 1.84 KB
/
rofi-lpass
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
#!/bin/bash
set -e
set -o pipefail
function print-account-list() {
lpass ls --format "%/as%ag - %an (%au) [%ai]" 2>&1
}
function copy-account-field() {
lpass show "--${2}" "$1" 2>/dev/null | xsel --clipboard --input --selectionTimeout 20000
}
function open-account-url() {
local url
url="$(lpass show --url "$1")"
if [[ -n $url ]]; then
xdg-open "$url" >/dev/null 2>/dev/null
else
exit 2
fi
}
function is-actual-url() {
local url="$1"
if [[ -n $url && "$url" != " " && "$url" != "http://" && "$url" != "https://" ]]; then
return 0
else
return 1
fi
}
function show-account-options() {
local id="$1"
echo ">> Copy password [$id]"
echo ">> Copy username [$id]"
url=$(lpass show --url "$id")
if is-actual-url "$url"; then
echo ">> Open $url [$id]"
echo ">> Copy URL [$id]"
fi
echo ">> Copy ID [$id]"
}
function is-entry-selected() {
if [[ -n "$*" ]]; then
return 0
else
return 1
fi
}
function id-in-selection() {
echo "$1" | grep -oE '\[[0-9]+\]$' | tr -d '[]'
}
function debug() {
echo "$*" > /dev/stderr
}
if is-entry-selected "$1"; then
selected="$1"
id="$(id-in-selection "$selected")"
if [[ -n $id ]]; then
case "$selected" in
'>> Copy password'*)
copy-account-field "$id" password ;;
'>> Copy username'*)
copy-account-field "$id" username ;;
'>> Copy URL'*)
copy-account-field "$id" url ;;
'>> Copy ID'*)
copy-account-field "$id" id ;;
'>> Open'*)
open-account-url "$id" ;;
*)
show-account-options "$id" ;;
esac
else
echo "Could not detect the entry ID of \"${selected}\""
exit 1
fi
else
print-account-list
fi