diff --git a/debian/changelog b/debian/changelog index 9b395c03..1cccd817 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,11 @@ byobu (4.54) unreleased; urgency=low - * UNRELEASED + * usr/lib/byobu/include/layout, usr/lib/byobu/include/Makefile.am, + usr/share/byobu/keybindings/f-keys.tmux, + usr/share/byobu/keybindings/f-keys.tmux.disable, + usr/share/doc/byobu/help.tmux.txt: LP: #902416 + - new feature to save layouts using ctrl-shift-F8, and restore layouts + using shift-F8 -- Dustin Kirkland Thu, 08 Dec 2011 12:15:18 -0600 diff --git a/usr/lib/byobu/include/Makefile.am b/usr/lib/byobu/include/Makefile.am index f1a49401..92014cd1 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 dirs mondrian notify_osd shutil +inclibdir_SCRIPTS = common constants dirs layout mondrian notify_osd shutil diff --git a/usr/lib/byobu/include/layout b/usr/lib/byobu/include/layout new file mode 100755 index 00000000..7760f3f3 --- /dev/null +++ b/usr/lib/byobu/include/layout @@ -0,0 +1,115 @@ +#!/bin/sh -e +# +# layout: save and restore byobu layouts +# Copyright (C) 2011 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 . + +PKG="byobu" +[ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc" +[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX +. "${BYOBU_PREFIX}/lib/${PKG}/include/common" + +# Get the layouts directory +DIR="$BYOBU_CONFIG_DIR/layouts" +mkdir -p "$DIR" +PRESETS="even-horizontal even-vertical main-horizontal main-vertical tiled" +current_panes=$(tmux list-panes | wc -l) + +list_layouts() { + echo + echo "Restore layout with , save a layout with " + echo + echo "Byobu Saved Layouts" + local count=0 i= desc= count= p= + for i in $PRESETS "$DIR"/*; do + desc=${i##*/} + count=$(expr $count + 1) + [ -f "$i" ] && p=$(head -n1 "$i") + [ -n "$p" ] && p=" ($p splits)" + echo " $count. $desc$p" + done + echo + _RET="$count" +} + +case "$1" in + "save") + layout=$(tmux list-windows | grep "(active)$" | sed -e "s/.*\[layout //" -e "s/\] (active)$//") + panes=$(tmux list-panes | wc -l) + if [ -n "$2" ]; then + name="$2" + else + while true; do + list_layouts + echo -n "Enter a unique name to save this layout: " + name=$(head -n1) + valid=1 + for i in $PRESETS "$DIR"/*; do + i=${i##*/} + if [ "$i" = "$name" ]; then + valid=0 + fi + done + [ "$valid" = "1" ] && break + done + fi + printf "$panes\n$layout\n" > "$BYOBU_CONFIG_DIR/layouts/$name" + ;; + "restore") + # List the saved layouts, prompt the user to select one + list_layouts + count="$_RET" + while true; do + echo -n "Select a layout to restore [1-$count]: " + selected=$(head -n1) + if [ -n "$selected" ] && [ $selected -le $count ] && [ $selected -ge 1 ]; then + break + fi + done + # Get the details of the selected layout + count=0 + panes= + layout= + for i in $PRESETS "$DIR"/*; do + count=$(expr $count + 1) + if [ $count -eq $selected ]; then + if [ -f "$i" ]; then + panes=$(head -n1 "$i") + layout=$(tail -n1 "$i") + else + if [ $current_panes -eq 1 ]; then + panes=4 + else + panes=0 + fi + layout="$i" + fi + break + fi + done + # Create panes if nececessary to restore the layout + while [ $(tmux list-panes | wc -l) -lt $panes ]; do + tmux split-window + done + # Finally, restore the layout and refresh + tmux select-layout "$layout" + tmux source "$BYOBU_PREFIX/share/byobu/profiles/tmuxrc" + ;; + *) + echo "ERROR: Invalid argument, try [save|restore]" 2>&1 + exit 1 + ;; +esac diff --git a/usr/share/byobu/keybindings/f-keys.tmux b/usr/share/byobu/keybindings/f-keys.tmux index 93f770e4..ba3cfb80 100644 --- a/usr/share/byobu/keybindings/f-keys.tmux +++ b/usr/share/byobu/keybindings/f-keys.tmux @@ -1,9 +1,9 @@ ############################################################################### # byobu's tmux f-key keybindings # -# Copyright (C) 2011 Dustin Kirkland +# Copyright (C) 2011 Dustin Kirkland # -# Authors: 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 @@ -60,6 +60,8 @@ bind-key -n M-NPage copy-mode \; send-keys NPage bind-key -n M-PPage copy-mode \; send-keys PPage bind-key -n F8 command-prompt -p "(rename-window)" "rename-window %%" bind-key -n C-F8 new-window -d "byobu-select-profile -r" +bind-key -n C-S-F8 command-prompt -p "Save byobu layout as:" "run-shell '$BYOBU_PREFIX/lib/byobu/include/layout save %%'" +bind-key -n S-F8 new-window -k "$BYOBU_PREFIX/lib/byobu/include/layout restore; clear; $SHELL" bind-key -n F9 new-window -k -n config byobu-config bind-key -n M-F11 break-pane bind-key -n C-F11 join-pane -h -s :. -t :-1 diff --git a/usr/share/byobu/keybindings/f-keys.tmux.disable b/usr/share/byobu/keybindings/f-keys.tmux.disable index 561c0184..209f7624 100644 --- a/usr/share/byobu/keybindings/f-keys.tmux.disable +++ b/usr/share/byobu/keybindings/f-keys.tmux.disable @@ -1,9 +1,9 @@ ############################################################################### # disable byobu's tmux f-key keybindings # -# Copyright (C) 2011 Dustin Kirkland +# Copyright (C) 2011 Dustin Kirkland # -# Authors: 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 @@ -56,6 +56,8 @@ unbind-key -n M-NPage unbind-key -n M-PPage unbind-key -n F8 unbind-key -n C-F8 +unbind-key -n C-S-F8 +unbind-key -n S-F8 unbind-key -n F9 unbind-key -n M-F11 unbind-key -n C-F11 diff --git a/usr/share/doc/byobu/help.tmux.txt b/usr/share/doc/byobu/help.tmux.txt index 9e1690c9..96f765aa 100644 --- a/usr/share/doc/byobu/help.tmux.txt +++ b/usr/share/doc/byobu/help.tmux.txt @@ -26,6 +26,8 @@ and some convenient keybindings: Alt-PageUp/PageDown Enter and move through scrollback F8 Change the current window's name Ctrl-F8 Change status bar's color randomly + Shift-F8 Restore a split-pane layout + Ctrl-Shift-F8 Save the current split-pane layout F9 Launch byobu-config window F10 * Used by X11 * F11 * Used by X11 *