From d84b65956ad59636c204f3faa2b8eff26eaff8e6 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Fri, 18 Oct 2013 16:28:54 -0500 Subject: [PATCH] * usr/bin/byobu-select-session: LP: #1241785 - rework session selecting, especially when nesting - support an environment variable BYOBU_NESTING=1 which users can set to force nesting (rather than modifying the TERM variable which other programs rely upon) - add an interactive step, where users can immediately choose to run in a nested session --- debian/changelog | 7 +++++++ usr/bin/byobu-select-session | 36 ++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index fc12649b..1db03525 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,13 @@ byobu (5.61) unreleased; urgency=low usr/share/byobu/pixmaps/byobu.svg: - add a new banner image - use a green color for the branches in the logo + * usr/bin/byobu-select-session: LP: #1241785 + - rework session selecting, especially when nesting + - support an environment variable BYOBU_NESTING=1 which users can + set to force nesting (rather than modifying the TERM variable + which other programs rely upon) + - add an interactive step, where users can immediately choose to + run in a nested session -- Dustin Kirkland Sat, 21 Sep 2013 09:42:30 -0500 diff --git a/usr/bin/byobu-select-session b/usr/bin/byobu-select-session index 9e0a99b7..9f626643 100755 --- a/usr/bin/byobu-select-session +++ b/usr/bin/byobu-select-session @@ -30,7 +30,7 @@ SHELL = os.getenv("SHELL", "/bin/bash") HOME = os.getenv("HOME") BYOBU_CONFIG_DIR = os.getenv("BYOBU_CONFIG_DIR", HOME + "/.byobu") BYOBU_BACKEND = os.getenv("BYOBU_BACKEND", "tmux") -choice = "" +choice = -1 sessions = [] text = [] @@ -96,6 +96,24 @@ def attach_session(session): else: os.execvp("screen", ["", "-AOxRR", session_name]) +# Confirm nested session, if necessary +if os.getenv("BYOBU_NESTING", "0") != "1": + if (BYOBU_BACKEND == "tmux" and os.getenv("TMUX")) or (BYOBU_BACKEND == "screen" and "screen" in os.getenv("TERM")): + sys.stderr.write("WARNING: Sessions should be nested with care.\n") + try: + nest = raw_input("Are you sure you want to run Byobu inside another session? [y/N]: ") + if nest != "Y" and nest != "y": + sys.exit(1) + else: + if os.getenv("TMUX"): + os.unsetenv("TMUX") + except KeyboardInterrupt: + sys.stdout.write("\n") + sys.exit(1) + except: + sys.stdout.write("\n") + sys.exit(1) + sessions = get_sessions() show_shell = os.path.exists("%s/.always-select" % (BYOBU_CONFIG_DIR)) @@ -119,29 +137,23 @@ if len(sessions) > 1: break else: tries += 1 - choice = "" + choice = -1 sys.stderr.write("\nERROR: Invalid input\n") except KeyboardInterrupt: - print() + sys.stdout.write("\n") sys.exit(0) except: - if choice == "": + if choice == "" or choice == -1: choice = 1 break tries += 1 - choice = "" + choice = -1 sys.stderr.write("\nERROR: Invalid input\n") elif len(sessions) == 1: # Auto-select the only session choice = 1 - if BYOBU_BACKEND == "tmux" and os.getenv("TMUX"): - sys.stderr.write("ERROR: Sessions should be nested with care. Unset $TMUX to force.\n") - sys.exit(1) - elif BYOBU_BACKEND == "screen" and re.match("screen", os.getenv("TERM")): - sys.stderr.write("ERROR: Sessions should be nested with care. Remove 'screen' from $TERM to force.\n") - sys.exit(1) -if choice: +if choice >= 1: if sessions[choice - 1] == "NEW": # Create a new session if BYOBU_BACKEND == "tmux":