-
Notifications
You must be signed in to change notification settings - Fork 0
/
opass-completion.bash
32 lines (26 loc) · 1.03 KB
/
opass-completion.bash
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
#/usr/bin/env bash
_opass_completions() {
local tags=$(awk -F '=' '/\[tags\]/,0 {print $1}' $HOME/.opass/cache \
| awk 'NR!=1' \
| sort \
| tr -d '[[:blank:]]' \
| tr '\n' ' ')
local tagged_items=$(awk -F '=' '/\[tags\]/,0 {tags[$1]=$2} END \
{ \
for (tag in tags) { \
split(tags[tag], items, ",")
for (i in items) { \
print(sprintf("%s\/%s", tag, items[i])) \
} \
} \
}' $HOME/.opass/cache \
| sort \
| tr -d '[[:blank:]]' \
| tr '\n' ' ')
if [[ "${COMP_WORDS[1]}" == *\/ ]]; then
COMPREPLY+=($(compgen -S / -W "$tagged_items"))
else
COMPREPLY+=($(compgen -S / -W "$tags"))
fi
}
complete -o nospace -F _opass_completions opass