mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-22 22:34:23 -07:00
* usr/bin/byobu-select-session:
- add session selection support for tmux
This commit is contained in:
parent
0f46cd5a6a
commit
01c90a6e8d
2 changed files with 52 additions and 18 deletions
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -72,6 +72,8 @@ byobu (4.30) unreleased; urgency=low
|
||||||
Vancouver
|
Vancouver
|
||||||
- fix flag path; simplify coloring
|
- fix flag path; simplify coloring
|
||||||
* usr/lib/byobu/reboot_required:
|
* usr/lib/byobu/reboot_required:
|
||||||
|
* usr/bin/byobu-select-session:
|
||||||
|
- add session selection support for tmux
|
||||||
|
|
||||||
-- Dustin Kirkland <kirkland@ubuntu.com> Thu, 11 Aug 2011 10:31:31 -0500
|
-- Dustin Kirkland <kirkland@ubuntu.com> Thu, 11 Aug 2011 10:31:31 -0500
|
||||||
|
|
||||||
|
|
|
@ -28,23 +28,45 @@ BYOBU_BACKEND=os.getenv("BYOBU_BACKEND", "screen")
|
||||||
choice = ""
|
choice = ""
|
||||||
sessions = []
|
sessions = []
|
||||||
text = []
|
text = []
|
||||||
i = 0
|
|
||||||
|
|
||||||
output = commands.getoutput('%s -ls ' % BYOBU_BACKEND)
|
def get_sessions():
|
||||||
if output:
|
sessions = []
|
||||||
|
i = 0
|
||||||
|
if commands.getstatusoutput("command -v screen")[0] == 0:
|
||||||
|
output = commands.getoutput("screen -ls")
|
||||||
|
if output:
|
||||||
for s in output.split("\n"):
|
for s in output.split("\n"):
|
||||||
s = re.sub(r'\s+', ' ', s)
|
s = re.sub(r'\s+', ' ', s)
|
||||||
# Ignore hidden sessions (named sessions that start with a ".")
|
# Ignore hidden sessions (named sessions that start with a ".")
|
||||||
if s.find(" ") == 0 and len(s) > 1 and s.count("..") == 0:
|
if (s.find(" ") == 0 and len(s) > 1 and s.count("..") == 0):
|
||||||
text.append("Select %s" % s.strip())
|
text.append("screen: %s" % s.strip())
|
||||||
items = s.split(" ")
|
items = s.split(" ")
|
||||||
sessions.append(items[1])
|
sessions.append("screen____%s" % items[1])
|
||||||
i += 1
|
i += 1
|
||||||
|
if commands.getstatusoutput("command -v tmux")[0] == 0:
|
||||||
|
output = commands.getoutput("tmux list-sessions")
|
||||||
|
if output:
|
||||||
|
for s in output.split("\n"):
|
||||||
|
text.append("tmux: %s" % s.strip())
|
||||||
|
items = s.split(":")
|
||||||
|
sessions.append("tmux____%s" % items[0])
|
||||||
|
i += 1
|
||||||
|
return sessions
|
||||||
|
|
||||||
|
def attach_session(session):
|
||||||
|
print("Attaching: [%s]\n" % session)
|
||||||
|
items = session.split("____", 2)
|
||||||
|
if items[0] == "tmux":
|
||||||
|
os.execvp("tmux", ["", "attach", "-t", items[1]])
|
||||||
|
else:
|
||||||
|
os.execvp("screen", ["", "-AOxRR", items[1]])
|
||||||
|
|
||||||
|
sessions = get_sessions()
|
||||||
|
|
||||||
show_shell = os.path.exists("%s/.always-select" % (BYOBU_CONFIG_DIR))
|
show_shell = os.path.exists("%s/.always-select" % (BYOBU_CONFIG_DIR))
|
||||||
if i>1 or show_shell:
|
if len(sessions) > 1 or show_shell:
|
||||||
sessions.append("NEW")
|
sessions.append("NEW")
|
||||||
text.append("Create a new Byobu session")
|
text.append("Create a new Byobu session (%s)" % BYOBU_BACKEND)
|
||||||
sessions.append("SHELL")
|
sessions.append("SHELL")
|
||||||
text.append("Run a shell without Byobu (%s)" % SHELL)
|
text.append("Run a shell without Byobu (%s)" % SHELL)
|
||||||
|
|
||||||
|
@ -75,18 +97,28 @@ if len(sessions) > 1:
|
||||||
choice = ""
|
choice = ""
|
||||||
sys.stderr.write("\nERROR: Invalid input\n");
|
sys.stderr.write("\nERROR: Invalid input\n");
|
||||||
elif len(sessions) == 1:
|
elif len(sessions) == 1:
|
||||||
# Attach to the chosen session; must use the binary, not the wrapper!
|
# Attach to the only session; must use the binary, not the wrapper!
|
||||||
os.execvp(BYOBU_BACKEND, ["", "-AOxRR"])
|
if BYOBU_BACKEND == "tmux":
|
||||||
|
os.execvp("tmux", ["", "attach"])
|
||||||
|
else:
|
||||||
|
os.execvp("screen", ["", "-AOxRR"])
|
||||||
|
|
||||||
if choice:
|
if choice:
|
||||||
if sessions[choice-1] == "NEW":
|
if sessions[choice-1] == "NEW":
|
||||||
# Create a new session
|
# Create a new session
|
||||||
|
if BYOBU_BACKEND == "tmux":
|
||||||
|
os.execvp("byobu", ["", "new-session", SHELL])
|
||||||
|
else:
|
||||||
os.execvp("byobu", ["", SHELL])
|
os.execvp("byobu", ["", SHELL])
|
||||||
elif sessions[choice-1] == "SHELL":
|
elif sessions[choice-1] == "SHELL":
|
||||||
os.execvp(SHELL, [SHELL])
|
os.execvp(SHELL, [SHELL])
|
||||||
else:
|
else:
|
||||||
# Attach to the chosen session; must use the binary, not the wrapper!
|
# Attach to the chosen session; must use the binary, not the wrapper!
|
||||||
os.execvp(BYOBU_BACKEND, ["", "-AOxRR", sessions[choice-1]])
|
attach_session(sessions[choice-1])
|
||||||
|
|
||||||
# No valid selection, default to the youngest session, create if necessary
|
# No valid selection, default to the youngest session, create if necessary
|
||||||
os.execvp("byobu", ["", "-AOxRR"])
|
if BYOBU_BACKEND == "tmux":
|
||||||
|
args = ""
|
||||||
|
else:
|
||||||
|
args = "-AOxRR"
|
||||||
|
os.execvp("byobu", ["", args])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue