-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpf
executable file
·86 lines (77 loc) · 2.17 KB
/
pf
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
#!/bin/sh
# vim: foldmethod=marker foldmarker={,}
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2020 Jeremy Brubaker <jbru362@gmail.com>
#
# abstract: present a menu of pass(1) entries that match <tag>
#
print_help() {
cat <<EOF
Usage: pf [OPTION] <tag>
Search the pass(1) database for <tag> and copy the password
to the clipboard or display the entry
-d display selected entry and exit
-m display selected entries until EOF given
-v output version information and exit
-h display this help and exit
EOF
}
print_version() {
cat <<EOF
pf 1.0
Copyright (C) 2021 Orion Arts
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jeremy Brubaker.
EOF
}
# Process options {
#
REPEAT=0
COPY='-c'
while getopts "dmvh" opt; do
case $opt in
d) COPY= ;;
m) REPEAT=1 ; COPY= ;;
v) print_version; exit ;;
h) print_help; exit ;;
*) print_help; exit ;;
esac
done
shift "$(($OPTIND-1))"
# }
if test $# -eq 0; then
printf "%s\n" "No tag given"
exit
fi
list=$( pass grep $1 | \
sed 's/\x1b\[[0-9;]*[a-zA-Z]//g' | \
awk '/:/ { print substr ($1, 1, length ($1) - 1) }' \
)
if test -z "$list"; then
printf "%s\n" "No matching entries found."
exit
fi
printf "%s" "Select entry to display."
if test $REPEAT -eq 1; then
printf "%s" " Ctrl+D to quit"
fi
echo
select p in $list; do
pass $COPY $p
test $REPEAT -eq 0 && break
done