-
Notifications
You must be signed in to change notification settings - Fork 0
/
keepassxc-open-all-urls.sh
executable file
·74 lines (64 loc) · 2.47 KB
/
keepassxc-open-all-urls.sh
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
#!/usr/bin/env bash
DESCRIPTION="Interactively open the urls for all passwords within a keepass database file (requires keepassxc.cli)"
USAGE="keepassxc-open-all-urls.sh [OPTIONS] keepass-db
keepass-db The path to the keepass database that should be parsed
Options:
-b, --browser <browser-command> The command to launch your browser. Will be called as such: '<command> %url%'
-c, --cli <keepassxc.cli-command> The command to execute keepassxc.cli. Not required if it can be found in your system PATH
-g, --group <group-path> Only show password entries for the given group
-y, --noninteractive Open all urls without waiting for user interaction
-h, --help Show this message"
. "$(dirname "$BASH_SOURCE")/lib/parse_args.sh"
KEYWORDS=("-b" "--browser" "-g" "--group" "-c" "--cli" "-y;bool" "--noninteractive;bool")
REQUIRED=("keepass-db")
parse_args __DESCRIPTION "$DESCRIPTION" __USAGE "$USAGE" "$@"
browser_cmd="${KW_ARGS['-b']-}"
browser_cmd="${KW_ARGS['--browser']-${browser_cmd}}"
keepass_cli="${KW_ARGS['-c']-keepassxc.cli}"
keepass_cli="${KW_ARGS['--cli']-$keepass_cli}}"
keepass_group="${KW_ARGS['--group']-${KW_ARGS['-g']}}"
set_trap 2
set -e
if [[ -z "$browser_cmd" ]]
then
for cmd in xdg-open firefox chromium chrome
do
command -v "$cmd" > /dev/null && {
browser_cmd="$cmd"
break
} || true
done
elif ! command -v "$browser_cmd" > /dev/null
then
echo "ERROR: Could not find the specified browser command '$browser_cmd'!"
exit 2
fi
if [[ -z "$browser_cmd" ]]
then
echo "ERROR: Could not find any browser! Please specify a browser command/executable " \
"with -b or --browser"
exit 2
fi
echo "Using browser command '$browser_cmd'..."
read -rs -p "Please enter the database password for '$(basename "${NAMED_ARGS['keepass-db']}")':" pw
echo ""
while read -r -u 3 entry
do
url="$(echo "$pw" \
| "$keepass_cli" show -a URL "${NAMED_ARGS['keepass-db']}" "$entry" \
2>/dev/null || true)"
if [[ -z "$url" ]]
then
echo "No URL for entry \"$entry\"..."
else
echo "Opening URL for entry \"$entry\"..."
"${browser_cmd}" "$url"
fi
if [[ -z "${KW_ARGS['--noninteractive']-${KW_ARGS['-y']}}" ]]
then
echo "[Enter] to proceed..."
read -s
fi
done 3< <(echo "$pw" \
| "$keepass_cli" ls -Rf "${NAMED_ARGS['keepass-db']}" "${keepass_group-/}" \
2> /dev/null)