aboutsummaryrefslogtreecommitdiff
path: root/.local/share/pass-extensions/names.bash
blob: aa42ebf5949aa4b404f837970581137217331409 (plain)
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
#!/bin/bash
# list all passwords in store

pass_dir="$(pass directory)"
[ $? -ne 0 ] && exit 1
cd "$pass_dir"

usage() {
	cat << EOF
usage:
	pass names [-hl]

options:
	-l	ignore symbolic links in password store
	-h	show this help
EOF
	exit $1
}

ARGC=0
while getopts lh OPT; do
	[ $OPTIND -gt $ARGC ] && ARGC=$OPTIND
	case $OPT in
		l)
			opt_ignore_symlinks=y
			;;
		h) usage 0 ;;
		\?|*) usage 1 ;;
	esac
done

find_args=()

if [ -n "$opt_ignore_symlinks" ] ; then
	find_args+=(-P) # ignore symbolic links
else
	find_args+=(-L) # follow symbolic links
fi
find_args+=(.)
find_args+=(-type d -name .git -prune) # skip .git directory
find_args+=(-o -type d -name .extensions -prune) # skip .extensions directory
find_args+=(-o -type f -name '*.gpg') # only .gpg files
find_args+=(-print)

find "${find_args[@]}" | cut -c3- | rev | cut -c5- | rev