-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpass-util
More file actions
executable file
·47 lines (41 loc) · 1.24 KB
/
pass-util
File metadata and controls
executable file
·47 lines (41 loc) · 1.24 KB
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
#!/usr/bin/env bash
set -euo pipefail
# Usage: see below
#
# This is a simple script implementing some missing subcommands from
# Pass, most notably a straightforward noninteractive way to update a
# password without overwriting additional metadata/TOTP, and commands
# to extract just the password or just the OTP seed rather than the
# whole file.
if [[ -n "${PASS_UTIL_EDITOR:-}" ]]; then
sed -i "1s/.*/$(sed <<< "${PASS_UTIL_NEW_PASS}" 's/[\/&]/\\&/g')/" "$1"
exit
fi
usage() {
cat <<"EOF" >&2
usage:
pass-util [passwd] example.com/user@example.com [linum]
pass-util [passwd-]set example.com/user@example.com new-password
pass-util otp example.com/user@example.com
pass-util otp-code example.com/user@example.com
EOF
exit 1
}
case "$#" in
0) usage ;;
1) cmd="passwd" ;;
2) if [[ "$2" =~ ^[0-9]+$ ]]; then
cmd="passwd"
else
cmd="$1"; shift
fi ;;
3) cmd="$1"; shift ;;
*) usage ;;
esac
case "${cmd}" in
passwd) pass "$1" | sed -n "${2:-1}"p ;;
set|passwd-set) PASS_UTIL_EDITOR=1 PASS_UTIL_NEW_PASS="$2" EDITOR="$0" pass edit "$1" ;;
otp) pass "$1" | sed -nr 's|^otpauth://.*secret=([^&]+).*|\1|p' ;;
otp-code) pass otp "$1" ;;
*) usage ;;
esac