File: get-gpg-key-id-by-email.sh

package info (click to toggle)
libfyaml 0.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,684 kB
  • sloc: ansic: 51,709; asm: 8,692; sh: 1,185; makefile: 545; python: 24
file content (20 lines) | stat: -rwxr-xr-x 456 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

# either use the supplied email address, or the current git user's email
if [ "x$1" != "x" ] ; then
	email="$1"
else
	email=`git config user.email`
fi
last=""
id=""
gpg --list-secret-keys | \
	while read line; do
		if [[ $line =~ ^uid\ .* ]] ; then
			temail=`echo $line | cut -d'<' -f2 | cut -d'>' -f1`
			if [[ "$email" == "$temail" && $last =~ ^sec\ .* ]]; then
				echo $last | cut -d/ -f 2 | cut -d' ' -f1
			fi
		fi
		last="$line"
	done