-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathage.bash
executable file
·59 lines (50 loc) · 1.32 KB
/
age.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
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
#!/bin/bash
# - assume the password is stored in the first line of a password-file
# - find the latest git revision that changes that line
# - show all passwords by age
PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
export GIT_DIR="${PASSWORD_STORE_GIT:-$PREFIX}/.git"
git_revisions() {
[[ -d $GIT_DIR ]] || return
local path="$1"
local passfile="$path.gpg"
git log --format=%H -- $passfile
}
git_revision() {
[[ -d $GIT_DIR ]] || return
local path="$1"
local revision="$2"
local passfile="$path.gpg"
git show $revision:$passfile | $GPG -d "${GPG_OPTS[@]}" | head -n 1
}
oldest_password_change() {
[[ -d $GIT_DIR ]] || die "Error: the password store is not a git repository. Try \"$PROGRAMgit init\"."
local path="$1"
check_sneaky_paths "$path"
git_revisions "$path" | while read revision
do
if [ -z "$password" ]; then
password="$(git_revision $path $revision)"
else
if [ "$password" != "$(git_revision $path $revision)" ]; then
break
fi
fi
echo $revision
done | tail -n 1
}
help_age() {
echo "Usage:"
echo " pass age PASS-NAME"
}
cmd_age() {
local path="$1"
check_sneaky_paths "$path"
local oldest=$(oldest_password_change "$path")
git show -s --format="%ct%x09%cr%x09"$path"" "$oldest"
}
case $1 in
--help) help_age ;;
"") help_age ;;
*) cmd_age "$@" ;;
esac