From f50e5bb5bf44883246fa8bb2ebca35b3735859a5 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 14 Nov 2011 17:31:32 -0600 Subject: [PATCH] * usr/bin/byobu-select-profile, usr/share/byobu/keybindings/f- keys.tmux, usr/share/byobu/keybindings/f-keys.tmux.disable, usr/share/doc/byobu/help.tmux.txt: LP: #817686 - add a couple of (tmux-only) modes to byobu-select-profile, which can automatically change the background color of the status bar, based on the systems hostname, ip address, or just at random - map this to Ctrl-F8 --- debian/changelog | 7 ++++ usr/bin/byobu-select-profile | 42 +++++++++++++++++++ usr/share/byobu/keybindings/f-keys.tmux | 1 + .../byobu/keybindings/f-keys.tmux.disable | 1 + usr/share/doc/byobu/help.tmux.txt | 3 +- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index de58e95c..195476a5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,13 @@ byobu (4.48) unreleased; urgency=low * usr/share/byobu/status/statusrc: - fix reference to non-existent variable, MONITORED_INTERFACE; should be MONITORED_NETWORK + * usr/bin/byobu-select-profile, usr/share/byobu/keybindings/f- + keys.tmux, usr/share/byobu/keybindings/f-keys.tmux.disable, + usr/share/doc/byobu/help.tmux.txt: LP: #817686 + - add a couple of (tmux-only) modes to byobu-select-profile, which can + automatically change the background color of the status bar, based + on the systems hostname, ip address, or just at random + - map this to Ctrl-F8 -- Dustin Kirkland Wed, 09 Nov 2011 17:54:11 -0600 diff --git a/usr/bin/byobu-select-profile b/usr/bin/byobu-select-profile index f53a3e88..45dd2229 100755 --- a/usr/bin/byobu-select-profile +++ b/usr/bin/byobu-select-profile @@ -167,6 +167,28 @@ setcolor() { touch "$BYOBU_RUN_DIR/reload-required" } +get_contrast() { + # See section 2.2: http://www.w3.org/TR/AERT + local hex="$(echo "$1" | sed "s/\(..\)\(..\)\(..\)/\1 \2 \3/")" + local bright=$(echo $hex | awk --non-decimal-data '{printf "%0.0f",(("0x"$1)*299+("0x"$2)*587+("0x"$3)*114)/1000}') + if [ $bright -ge 130 ]; then + _RET="black" + else + _RET="white" + fi +} + +setcolor_tmux() { + dark="$1" + get_contrast "$dark" + light="$_RET" + accent="magenta" + highlight="red" + monochrome="0" + printf "BYOBU_DARK=\"#$dark\"\nBYOBU_LIGHT=$light\nBYOBU_ACCENT=$accent\nBYOBU_HIGHLIGHT=$highlight\nMONOCHROME=$MONOCHROME" > "$FILE".tmux + tmux source "$BYOBU_PREFIX/share/byobu/profiles/tmuxrc" +} + if [ $# -eq 0 ]; then prompt "background" prompt "foreground" @@ -187,6 +209,26 @@ else shift break ;; + -h|--hostname) + color=$(hostname | md5sum | head -c 6) + setcolor_tmux "$color" + shift + break + ;; + -i|--ip) + [ -r "$BYOBU_CONFIG_DIR/statusrc" ] && . "$BYOBU_CONFIG_DIR/statusrc" + . $BYOBU_PREFIX/lib/$PKG/ip_address + color=$(__ip_address t| md5sum | head -c 6) + setcolor_tmux "$color" + shift + break + ;; + -r|--random) + color=$(head -c 10 /dev/urandom | md5sum | head -c 6) + setcolor_tmux "$color" + shift + break + ;; *) usage exit 1 diff --git a/usr/share/byobu/keybindings/f-keys.tmux b/usr/share/byobu/keybindings/f-keys.tmux index 026a187f..2b7055db 100644 --- a/usr/share/byobu/keybindings/f-keys.tmux +++ b/usr/share/byobu/keybindings/f-keys.tmux @@ -59,6 +59,7 @@ bind-key -n F7 copy-mode 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 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 81e83571..572625a7 100644 --- a/usr/share/byobu/keybindings/f-keys.tmux.disable +++ b/usr/share/byobu/keybindings/f-keys.tmux.disable @@ -55,6 +55,7 @@ unbind-key -n F7 unbind-key -n M-NPage unbind-key -n M-PPage unbind-key -n F8 +unbind-key -n C-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 a9501b78..d60f1d6d 100644 --- a/usr/share/doc/byobu/help.tmux.txt +++ b/usr/share/doc/byobu/help.tmux.txt @@ -24,7 +24,8 @@ and some convenient keybindings: Ctrl-F6 Kill split in focus F7 Enter scrollback history Alt-PageUp/PageDown Enter and move through scrollback - F8 Rename the current window + F8 Change the current window's name + Ctrl-F8 Change status bar's color randomly F9 Launch byobu-config window F10 * Used by X11 * F11 * Used by X11 *