summaryrefslogtreecommitdiffstats
path: root/gpg-agent.sh
blob: bace66da897357fb334655c9171b02b0621fa79a (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
#!/bin/bash
#----------------------------------------------------
# Author:       Florian "Bluewind" Pritz <flo@xssn.at>
#
# Licensed under WTFPL v2
#   (see COPYING for full license text)
#
#----------------------------------------------------
# make working with the agent easier and prevent
# starting multiple agents
#----------------------------------------------------
initgpg(){
	[[ -z $XDG_CONFIG_HOME ]] && XDG_CONFIG_HOME="$HOME/.config"
	[ -f "$XDG_CONFIG_HOME/disable-gpg-agent" ] && return 0
	if ! pgrep -u ${SUDO_USER:-$USER} -x gpg-agent >/dev/null; then
		/usr/bin/gpg-agent --daemon --enable-ssh-support >/dev/null
	fi
}

export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh

if [[ -n $DISPLAY ]]; then
	initgpg
fi