diff --git a/debian/changelog b/debian/changelog index a8b17e52..5517cbc6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,10 @@ byobu (5.3) unreleased; urgency=low * usr/share/man/man1/byobu.1: LP: #913817 - mention byobu-select-backend prominently in the manpage + [ Dustin Kirkland and Ryan Thompson ] + * usr/bin/byobu-reconnect-sockets, usr/bin/byobu-select-session: LP: #908944 + - improve support for importing X11 environment variables + -- Dustin Kirkland Sun, 08 Jan 2012 20:28:08 -0600 byobu (5.2-0ubuntu1) precise; urgency=low diff --git a/usr/bin/byobu-reconnect-sockets b/usr/bin/byobu-reconnect-sockets index f25d42cb..15d447a2 100755 --- a/usr/bin/byobu-reconnect-sockets +++ b/usr/bin/byobu-reconnect-sockets @@ -6,8 +6,10 @@ # byobu session. # # Copyright (C) 2009 Canonical Ltd. +# Copyright (C) 2012 Dustin Kirkland # -# Authors: Dustin Kirkland +# Authors: Dustin Kirkland +# Ryan C. Thompson # # 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 @@ -39,15 +41,61 @@ case "$-" in ;; esac +export_and_send () { + var="$1" + value="$(eval "echo \$$var")" + export "$var" + case $BYOBU_BACKEND in + tmux) + tmux setenv "$var" "$value" + ;; + *) + screen -X setenv "$var" "$value" + ;; + esac +} + +screen_update () { + # Ensure that screen's environment variables/values get propagated here + tempfile=$(mktemp -q) && { + for var in $VARS_TO_UPDATE; do + screen sh -c "echo export $var=\$$var >> \"$tempfile\"" + done + . "$tempfile" + rm -f "$tempfile" + } +} + +tmux_update () { + # Ensure that tmux's environment variables/values get propagated here + for var in $VARS_TO_UPDATE; do + expr="$(tmux showenv | grep "^$var=")" + if [ -n "$expr" ]; then + export "$expr" + fi + done +} + +# Pull environment variables/values from backend and update/export here +VARS_TO_UPDATE="DISPLAY DBUS_SESSION_BUS_ADDRESS SESSION_MANAGER GPG_AGENT_INFO" +case $BYOBU_BACKEND in + tmux) + tmux_update + ;; + screen) + screen_update + ;; +esac + # Establish gpg-agent socket, helps when reconnecting to a detached session -newest "$HOME/.gnupg/"gpg-agent-info-* && . "$_RET" && export GPG_AGENT_INFO +newest "$HOME/.gnupg/"gpg-agent-info-* && . "$_RET" && export_and_send 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" [ -r "$BYOBU_RUN_DIR/sockets" ] && . "$BYOBU_RUN_DIR/sockets" -export DBUS_SESSION_DBUS_ADDRESS -export SESSION_MANAGER +export_and_send DBUS_SESSION_BUS_ADDRESS +export_and_send SESSION_MANAGER # vi: syntax=sh ts=4 noexpandtab diff --git a/usr/bin/byobu-select-session b/usr/bin/byobu-select-session index 8da8efe2..81fbce69 100755 --- a/usr/bin/byobu-select-session +++ b/usr/bin/byobu-select-session @@ -2,8 +2,10 @@ # # byobu-select-session # Copyright (C) 2010 Canonical Ltd. +# Copyright (C) 2012 Dustin Kirkland # -# Authors: Dustin Kirkland +# Authors: Dustin Kirkland +# Ryan C. Thompson # # 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 @@ -18,7 +20,7 @@ # along with this program. If not, see . -import commands, os, re, sys +import commands, os, re, sys, subprocess PKG = "byobu" SHELL = os.getenv("SHELL", "/bin/bash") @@ -29,6 +31,8 @@ choice = "" sessions = [] text = [] +BYOBU_UPDATE_ENVVARS=["DISPLAY", "DBUS_SESSION_BUS_ADDRESS", "SESSION_MANAGER", "GPG_AGENT_INFO"] + def get_sessions(): sessions = [] i = 0 @@ -53,13 +57,26 @@ def get_sessions(): i += 1 return sessions +def update_environment(session): + backend, session_name = session.split("____", 2) + for var in BYOBU_UPDATE_ENVVARS: + value = os.getenv(var) + if value: + if backend == "tmux": + cmd = ["tmux", "setenv", "-t", session_name, var, value] + else: + cmd = ["screen", "-S", session_name, "-X", "setenv", var, value] + print "Sending variable: %s" % (cmd, ) + subprocess.call(cmd, stdout=open(os.devnull, "w")) + def attach_session(session): print("Attaching: [%s]\n" % session) - items = session.split("____", 2) - if items[0] == "tmux": - os.execvp("tmux", ["", "-2", "attach", "-t", items[1]]) + update_environment(session) + backend, session_name = session.split("____", 2) + if backend == "tmux": + os.execvp("tmux", ["", "-2", "attach", "-t", session_name]) else: - os.execvp("screen", ["", "-AOxRR", items[1]]) + os.execvp("screen", ["", "-AOxRR", session_name]) sessions = get_sessions()