mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 22:13:19 -07:00
* usr/bin/byobu-reconnect-sockets, usr/bin/byobu-select-session: LP: #908944
- improve support for importing X11 environment variables
This commit is contained in:
parent
5c69b1fb87
commit
a4a1c50df2
3 changed files with 79 additions and 10 deletions
4
debian/changelog
vendored
4
debian/changelog
vendored
|
@ -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 <kirkland@ubuntu.com> Sun, 08 Jan 2012 20:28:08 -0600
|
||||
|
||||
byobu (5.2-0ubuntu1) precise; urgency=low
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
# byobu session.
|
||||
#
|
||||
# Copyright (C) 2009 Canonical Ltd.
|
||||
# Copyright (C) 2012 Dustin Kirkland <dustin.kirkland@gmail.com>
|
||||
#
|
||||
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
|
||||
# Authors: Dustin Kirkland <dustin.kirkland@gmail.com>
|
||||
# Ryan C. Thompson <rct@thompsonclan.org>
|
||||
#
|
||||
# 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
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
#
|
||||
# byobu-select-session
|
||||
# Copyright (C) 2010 Canonical Ltd.
|
||||
# Copyright (C) 2012 Dustin Kirkland <dustin.kirkland@gmail.com>
|
||||
#
|
||||
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
|
||||
# Authors: Dustin Kirkland <dustin.kirkland@gmail.com>
|
||||
# Ryan C. Thompson <rct@thompsonclan.org>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue