=== modified file 'usr/bin/byobu-select-session'
--- usr/bin/byobu-select-session 2011-12-24 16:12:15 +0000
+++ usr/bin/byobu-select-session 2012-01-15 08:13:36 +0000
@@ -18,7 +18,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 +29,8 @@
sessions = []
text = []
+BYOBU_UPDATE_ENVVARS=["DISPLAY", "DBUS_SESSION_BUS_ADDRESS", "SESSION_MANAGER", "GPG_AGENT_INFO"]
+
def get_sessions():
sessions = []
i = 0
@@ -53,13 +55,26 @@
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()
=== added file 'usr/bin/byobu-update-environment'
--- usr/bin/byobu-update-environment 1970-01-01 00:00:00 +0000
+++ usr/bin/byobu-update-environment 2012-01-15 09:38:18 +0000
@@ -0,0 +1,69 @@
+#!/bin/sh
+#
+# byobu-update-environment - source this file to pull updated
+# environment from screen/tmux into a
+# running shell
+#
+# Copyright (C) 2011 Ryan C. Thompson???
+#
+# Authors: 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
+# 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 .
+
+PKG="byobu"
+[ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc"
+[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX
+. "${BYOBU_PREFIX}/lib/${PKG}/include/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
+
+VARS_TO_UPDATE="DISPLAY DBUS_SESSION_BUS_ADDRESS SESSION_MANAGER GPG_AGENT_INFO"
+
+screen_update () {
+ 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 () {
+ for var in $VARS_TO_UPDATE; do
+ expr="$(tmux showenv | grep "^$var")"
+ if [ -n "$expr" ]; then
+ export "$expr"
+ fi
+ done
+}
+
+case $BYOBU_BACKEND in
+ tmux)
+ tmux_update
+ ;;
+ *)
+ screen_update
+ ;;
+esac