#!/bin/sh
#
#    byobu-reconnect-sockets - source this file to re-establish
#                              GPG_AGENT_INFO and DBUS_SESSION_BUS_ADDRESS,
#                              useful when reconnecting to an existing
#                              byobu session.
#
#    Copyright (C) 2009 Canonical Ltd.
#
#    Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

PKG="byobu"
[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX
. "${BYOBU_PREFIX}/lib/${PKG}/.common"

case "$-" in
	*i*)
		# no-op
	;;
	*)
		echo 2>&1
		echo "ERROR: You must source this file, rather than execute it." 2>&1
		echo "  . $0" 2>&1
		echo 2>&1
		exit 1
	;;
esac

# Establish gpg-agent socket, helps when reconnecting to a detached session
newest "$HOME/.gnupg/"gpg-agent-info-* && . "$_RET" && export GPG_AGENT_INFO

# Reconnect dbus, source the most recently touched session-bus
# Sorry, ls -t is needed here, to sort by time
newest "$HOME/.dbus/session-bus/*" && . "$_RET" && export DBUS_SESSION_DBUS_ADDRESS

# vi: syntax=sh ts=4 noexpandtab
