From bbdc1e831a22a5edcdf5b0df42564bd47e6aaf46 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Wed, 7 Jul 2010 11:16:31 -0400 Subject: [PATCH] * usr/bin/byobu-select-session: - save a few forks, use regexes for screen -ls processing - fix select-session code, LP: #602750 --- debian/changelog | 4 +++- usr/bin/byobu-select-session | 29 ++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0d2f2fb6..0a0faf2b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,8 @@ byobu (2.82) unreleased; urgency=low - * UNRELEASED + * usr/bin/byobu-select-session: + - save a few forks, use regexes for screen -ls processing + - fix select-session code, LP: #602750 -- Dustin Kirkland Fri, 02 Jul 2010 10:02:18 -0500 diff --git a/usr/bin/byobu-select-session b/usr/bin/byobu-select-session index 5a60b708..b73169bd 100755 --- a/usr/bin/byobu-select-session +++ b/usr/bin/byobu-select-session @@ -18,27 +18,30 @@ # along with this program. If not, see . -import commands, os, sys +import commands, os, re, sys PKG = "byobu" SHELL = os.getenv("SHELL", "/bin/bash") -sessions = [] choice = "" -sessions.append(0) +sessions = [] +text = [] i = 0 -output = commands.getoutput('screen -ls "' + PKG + '" | sed "s/\s\+/ /g" | grep "^\s"') +output = commands.getoutput('screen -ls ' + PKG) if output: for s in output.split("\n"): - items = s.split(" ") - sessions.append(items[1]) - i += 1 + s = re.sub(r'\s+', ' ', s) + if s.find(" ") == 0 and len(s) > 1: + text.append(s) + items = s.split(" ") + sessions.append(items[1]) + i += 1 if i > 1: sys.stdout.write("\nByobu sessions...\n\n") tries = 0 while tries < 3: i = 1 - for s in output.split("\n"): + for s in text: sys.stdout.write(" %d. %s\n" % (i, s)) i += 1 sys.stdout.write(" %d. Create a new session\n" % i) @@ -64,8 +67,8 @@ if choice: # Create a new session os.execv("/usr/bin/byobu", ["", SHELL]) else: - # Attach to the chosen session - os.execv("/usr/bin/byobu", ["", "-AOxRR", sessions[choice]]) -else: - # No valid selection, default to the youngest session - os.execv("/usr/bin/byobu", ["", "-AOxRR"]) + # Attach to the chosen session; must use the 'screen' binary + os.execv("/usr/bin/screen", ["", "-AOxRR", sessions[choice-1]]) + +# No valid selection, default to the youngest session, create if necessary +os.execv("/usr/bin/byobu", ["", "-AOxRR"])