* usr/bin/byobu-select-session:

- save a few forks, use regexes for screen -ls processing
  - fix select-session code, LP: #602750
This commit is contained in:
Dustin Kirkland 2010-07-07 11:16:31 -04:00
commit bbdc1e831a
2 changed files with 19 additions and 14 deletions

4
debian/changelog vendored
View file

@ -1,6 +1,8 @@
byobu (2.82) unreleased; urgency=low 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 <kirkland@ubuntu.com> Fri, 02 Jul 2010 10:02:18 -0500 -- Dustin Kirkland <kirkland@ubuntu.com> Fri, 02 Jul 2010 10:02:18 -0500

View file

@ -18,17 +18,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import commands, os, sys import commands, os, re, sys
PKG = "byobu" PKG = "byobu"
SHELL = os.getenv("SHELL", "/bin/bash") SHELL = os.getenv("SHELL", "/bin/bash")
sessions = []
choice = "" choice = ""
sessions.append(0) sessions = []
text = []
i = 0 i = 0
output = commands.getoutput('screen -ls "' + PKG + '" | sed "s/\s\+/ /g" | grep "^\s"') output = commands.getoutput('screen -ls ' + PKG)
if output: if output:
for s in output.split("\n"): for s in output.split("\n"):
s = re.sub(r'\s+', ' ', s)
if s.find(" ") == 0 and len(s) > 1:
text.append(s)
items = s.split(" ") items = s.split(" ")
sessions.append(items[1]) sessions.append(items[1])
i += 1 i += 1
@ -38,7 +41,7 @@ if i > 1:
tries = 0 tries = 0
while tries < 3: while tries < 3:
i = 1 i = 1
for s in output.split("\n"): for s in text:
sys.stdout.write(" %d. %s\n" % (i, s)) sys.stdout.write(" %d. %s\n" % (i, s))
i += 1 i += 1
sys.stdout.write(" %d. Create a new session\n" % i) sys.stdout.write(" %d. Create a new session\n" % i)
@ -64,8 +67,8 @@ if choice:
# Create a new session # Create a new session
os.execv("/usr/bin/byobu", ["", SHELL]) os.execv("/usr/bin/byobu", ["", SHELL])
else: else:
# Attach to the chosen session # Attach to the chosen session; must use the 'screen' binary
os.execv("/usr/bin/byobu", ["", "-AOxRR", sessions[choice]]) os.execv("/usr/bin/screen", ["", "-AOxRR", sessions[choice-1]])
else:
# No valid selection, default to the youngest session # No valid selection, default to the youngest session, create if necessary
os.execv("/usr/bin/byobu", ["", "-AOxRR"]) os.execv("/usr/bin/byobu", ["", "-AOxRR"])