From 3a73583e914c4d826c3ab1d06e9f48770ca072c6 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Tue, 7 May 2013 13:15:07 -0500 Subject: [PATCH] * usr/bin/byobu, usr/lib/byobu/include/Makefile.am, usr/lib/byobu/include/tmux-detach-all-but-current-client, usr/share/byobu/keybindings/f-keys.tmux, usr/share/byobu/keybindings/f-keys.tmux.disable, usr/share/doc/byobu/help.tmux.txt: LP: #939870 - add a new keybinding, Alt-F6, which detaches all other clients + often used to maximize your tmux session, since tmux reduces the available size of your terminal to the smallest connected session --- debian/changelog | 9 ++++ usr/bin/byobu | 4 ++ usr/lib/byobu/include/Makefile.am | 2 +- .../tmux-detach-all-but-current-client | 46 +++++++++++++++++++ usr/share/byobu/keybindings/f-keys.tmux | 1 + .../byobu/keybindings/f-keys.tmux.disable | 1 + usr/share/doc/byobu/help.tmux.txt | 1 + 7 files changed, 63 insertions(+), 1 deletion(-) create mode 100755 usr/lib/byobu/include/tmux-detach-all-but-current-client diff --git a/debian/changelog b/debian/changelog index 49e01510..427fd2fb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,15 @@ byobu (5.38) unreleased; urgency=low * usr/bin/byobu-launch: - append, rather than prepend, $PROMPT_COMMAND, as double-semi-colons are illegal, thanks to Christian Mäder in github for patch + * usr/bin/byobu, usr/lib/byobu/include/Makefile.am, + usr/lib/byobu/include/tmux-detach-all-but-current-client, + usr/share/byobu/keybindings/f-keys.tmux, + usr/share/byobu/keybindings/f-keys.tmux.disable, + usr/share/doc/byobu/help.tmux.txt: LP: #939870 + - add a new keybinding, Alt-F6, which detaches all other clients + + often used to maximize your tmux session, since tmux reduces + the available size of your terminal to the smallest connected + session -- Dustin Kirkland Sun, 21 Apr 2013 11:11:01 -0500 diff --git a/usr/bin/byobu b/usr/bin/byobu index 510e5a6c..d268d5e3 100755 --- a/usr/bin/byobu +++ b/usr/bin/byobu @@ -2,6 +2,7 @@ # # byobu - wrapper script # Copyright (C) 2008-2009 Canonical Ltd. +# Copyright (C) 2008-2013 Dustin Kirkland # # Authors: Dustin Kirkland # @@ -59,6 +60,9 @@ esac # At this point, we're sure BYOBU_BACKEND is properly defined export BYOBU_BACKEND +# Store the parent tty +export BYOBU_TTY=$(tty) + # Add a version argument for debugging purposes if [ "$#" = "1" ]; then case "$1" in diff --git a/usr/lib/byobu/include/Makefile.am b/usr/lib/byobu/include/Makefile.am index a7555f10..6e9dcd72 100644 --- a/usr/lib/byobu/include/Makefile.am +++ b/usr/lib/byobu/include/Makefile.am @@ -1,2 +1,2 @@ inclibdirdir = $(prefix)/lib/@PACKAGE@/include -inclibdir_SCRIPTS = common constants cycle-status dirs mondrian notify_osd shutil ec2instancespricing.py +inclibdir_SCRIPTS = common constants cycle-status dirs mondrian notify_osd shutil ec2instancespricing.py tmux-detach-all-but-current-client diff --git a/usr/lib/byobu/include/tmux-detach-all-but-current-client b/usr/lib/byobu/include/tmux-detach-all-but-current-client new file mode 100755 index 00000000..571b5375 --- /dev/null +++ b/usr/lib/byobu/include/tmux-detach-all-but-current-client @@ -0,0 +1,46 @@ +#!/bin/sh +# +# tmux-detach-all-but-current-client +# Copyright (C) 2013 Dustin Kirkland +# +# 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 . + +a1= +a2= +tty1= +tty2= +# List all clients, ordered by most recent activity descending +for c in $(tmux list-clients -F "#{client_activity}___#{client_tty}" | sort -n -r); do + if [ -z "$a1" ]; then + a1=${c%%___*} + tty1=${c##*___} + elif [ -z "$a2" ]; then + a2=${c%%___*} + tty2=${c##*___} + fi + if [ -n "$a1" ] && [ -n "$a2" ]; then + if [ "$a1" = "$a2" ]; then + # Activity timestamps match in top 2 attached clients + # Let's not detach anyone here! + tmux display-message "Multiple active attached clients detected, refusing to detach" >/dev/null 2>&1 + elif [ -n "$tty1" ]; then + # Detach all but the current client, iterating across each + # Tempting to use detach-client -a -t here, but there's a bug + # in there, keeping that from working properly + tmux detach-client -t "$tty2" >/dev/null 2>&1 + a2= + fi + fi +done diff --git a/usr/share/byobu/keybindings/f-keys.tmux b/usr/share/byobu/keybindings/f-keys.tmux index fff5f0a0..cc4e8287 100644 --- a/usr/share/byobu/keybindings/f-keys.tmux +++ b/usr/share/byobu/keybindings/f-keys.tmux @@ -57,6 +57,7 @@ bind-key -n S-F5 new-window -k "$BYOBU_PREFIX/lib/byobu/include/cycle-status" \; bind-key -n C-F5 send-keys ". $BYOBU_PREFIX/bin/byobu-reconnect-sockets" \; send-keys Enter bind-key -n C-S-F5 new-window -d "byobu-select-profile -r" bind-key -n F6 detach +bind-key -n M-F6 run-shell '$BYOBU_PREFIX/lib/byobu/include/tmux-detach-all-but-current-client' bind-key -n S-F6 run-shell 'exec touch $BYOBU_RUN_DIR/no-logout' \; detach bind-key -n C-F6 kill-pane bind-key -n F7 copy-mode diff --git a/usr/share/byobu/keybindings/f-keys.tmux.disable b/usr/share/byobu/keybindings/f-keys.tmux.disable index 700e757d..0d2e5713 100644 --- a/usr/share/byobu/keybindings/f-keys.tmux.disable +++ b/usr/share/byobu/keybindings/f-keys.tmux.disable @@ -58,6 +58,7 @@ unbind-key -n S-F5 unbind-key -n C-F5 unbind-key -n C-S-F5 unbind-key -n F6 +unbind-key -n M-F6 unbind-key -n S-F6 unbind-key -n C-F6 unbind-key -n F7 diff --git a/usr/share/doc/byobu/help.tmux.txt b/usr/share/doc/byobu/help.tmux.txt index 06db0094..0b26f870 100644 --- a/usr/share/doc/byobu/help.tmux.txt +++ b/usr/share/doc/byobu/help.tmux.txt @@ -22,6 +22,7 @@ and some convenient keybindings: Ctrl-Shift-F5 Change status bar's color randomly F6 Detach session and then logout Shift-F6 Detach session and do not logout + Alt-F6 Detach all clients but yourself Ctrl-F6 Kill split in focus F7 Enter scrollback history Alt-PageUp/PageDown Enter and move through scrollback