From 954c3ef565c5fff5782c9f9f4f4e615658a3be45 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Tue, 12 Jan 2010 11:55:52 -0600 Subject: [PATCH] bin/byobu-launcher, bin/byobu-select-session, share/man/man1/byobu-select-session.1: add a dynamic prompt if automatically launching byobu on a server where multiple sessions exist, LP: #368963 --- debian/changelog | 4 ++ usr/bin/byobu-launcher | 3 +- usr/bin/byobu-select-session | 59 +++++++++++++++++++++++ usr/share/man/man1/byobu-select-session.1 | 20 ++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100755 usr/bin/byobu-select-session create mode 100644 usr/share/man/man1/byobu-select-session.1 diff --git a/debian/changelog b/debian/changelog index 448af13f..dfa93d0d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,10 @@ byobu (2.47) unreleased; urgency=low - usr/share/byobu/tests/byobu-time-notifications: relocate, rename, and install the notification timing tests, add a copyright header - AUTHORS, ChangeLog, NEWS: added + * bin/byobu-launcher, bin/byobu-select-session, + share/man/man1/byobu-select-session.1: add a dynamic prompt if + automatically launching byobu on a server where multiple sessions + exist, LP: #368963 [ Jason Cohen ] * usr/bin/byobu: check if our terminfo supports 256 colors, LP: #409353 diff --git a/usr/bin/byobu-launcher b/usr/bin/byobu-launcher index 2b9cd9bc..33a0345c 100755 --- a/usr/bin/byobu-launcher +++ b/usr/bin/byobu-launcher @@ -37,6 +37,5 @@ else rm -f "$RUN/$PKG.ssh-agent" ln -sf "$SSH_AUTH_SOCK" "$RUN/$PKG.ssh-agent" fi - # Re-attach to existing session - exec screen -xRR + exec byobu-select-session fi diff --git a/usr/bin/byobu-select-session b/usr/bin/byobu-select-session new file mode 100755 index 00000000..14c9e1a2 --- /dev/null +++ b/usr/bin/byobu-select-session @@ -0,0 +1,59 @@ +#! /usr/bin/env python +# +# byobu-select-session +# Copyright (C) 2010 Canonical Ltd. +# +# Authors: Dustin Kirkland +# +# 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 . + + +import commands, os, sys + +sessions = [] +choice = "" +sessions.append(0) +i = 0 +output = commands.getoutput('byobu -ls | sed "s/\s\+/ /g" | grep "^\s"') +if output: + for s in output.split("\n"): + 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"): + sys.stdout.write(" %d. %s\n" % (i, s)) + i += 1 + try: + choice = input("\nChoose [1-%d]: " % (i-1)) + if choice < 1 or choice >= i: + choice = "" + except: + tries += 1 + choice = "" + if choice: + break + else: + sys.stderr.write("\nERROR: Invalid input\n"); + +if choice: + # Attach to the chosen session + os.execv("/usr/bin/byobu", ["", "-x", sessions[choice]]) +else: + # No valid selection, default to the youngest session + os.execv("/usr/bin/byobu", ["", "-xRR"]) diff --git a/usr/share/man/man1/byobu-select-session.1 b/usr/share/man/man1/byobu-select-session.1 new file mode 100644 index 00000000..2e15e116 --- /dev/null +++ b/usr/share/man/man1/byobu-select-session.1 @@ -0,0 +1,20 @@ +.TH byobu\-select\-session 1 "12 Jan 2010" byobu "byobu" +.SH NAME +byobu\-select\-session \- select and connect to a byobu session + +.SH DESCRIPTION +\fBbyobu\-select\-profile\fP is an application that lists the available screen sessions running on the system, and prompts the user to select one. If an invalid selection is chosen 3 times in a row, the user is connected to the youngest session. If only one session exists, the user is connected to that session. If no sessions exist, a new session is created. + +.SH "SEE ALSO" +.PD 0 +.TP +\fBbyobu\fP(1), \fBscreen\fP(1) + +.TP +\fIhttp://launchpad.net/byobu\fP +.PD + +.SH AUTHOR +This manpage and the utility were written by Dustin Kirkland for Ubuntu systems (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 published by the Free Software Foundation. + +On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL.