From 694cdfa444085256cd7b981d557460cd144fdaa9 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Wed, 16 Nov 2011 19:13:55 -0600 Subject: [PATCH] * usr/bin/byobu-mondrian: - fix up naming, randomization, clean up color printing --- debian/changelog | 3 +- usr/bin/byobu-modrian | 64 ---------------------------- usr/bin/byobu-mondrian | 96 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 65 deletions(-) delete mode 100755 usr/bin/byobu-modrian create mode 100755 usr/bin/byobu-mondrian diff --git a/debian/changelog b/debian/changelog index 4eb8dc07..ba66178a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,9 +2,10 @@ byobu (4.49) unreleased; urgency=low * usr/bin/byobu-select-session: - fix 256-color tmux reattaches - * usr/bin/byobu-modrian: + * usr/bin/byobu-mondrian: - add a new, fun script - speed it up a bit + - fix up naming, randomization, clean up color printing -- Dustin Kirkland Mon, 14 Nov 2011 17:43:02 -0600 diff --git a/usr/bin/byobu-modrian b/usr/bin/byobu-modrian deleted file mode 100755 index 09d22326..00000000 --- a/usr/bin/byobu-modrian +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# -# byobu-modrian: randomly generate some Modrian art in tmux -# -# 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 . - -get_random_pane() { - local panes=$(tmux list-panes | wc -l) - r=$((RANDOM % 4)) - while [ $r = "$LAST_PANE" ]; do - r=$((RANDOM % 4)) - done - LAST_PANE="$r" - echo "$r" -} - -red_color=196 -yellow_color=226 -blue_color=57 -white_color=231 - -# Get number of splits -[ -n "$1" ] && TOTAL_SPLITS=$1 || TOTAL_SPLITS=10 -# Choose 1 red, 1 yellow, 1 blue -nums=$(rand -N 3 -M $TOTAL_SPLITS -u) -red=$(echo "$nums" | awk '{print $1}') -yellow=$(echo "$nums" | awk '{print $2}') -blue=$(echo "$nums" | awk '{print $3}') - -# Create some splits -tmux new-window -n modrian "solid_color $white_color" -tmux set-option -g pane-active-border-bg default -tmux set-option -g pane-active-border-fg default -for i in $(seq 0 $((TOTAL_SPLITS-1))); do - case $i in - $red) color=$red_color ;; - $yellow) color=$yellow_color ;; - $blue) color=$blue_color ;; - *) color=$white_color ;; - esac - CMD="solid_color $color" - [ "$((RANDOM % 2))" = "0" ] && SPLIT="-v" || SPLIT="-h" - if ! tmux split-window $SPLIT -t $(get_random_pane) "$CMD" ; then - case "$i" in - $red) red=$((red+1)) ;; - $yellow) yellow=$((yellow+1)) ;; - $blue) blue=$((blue+1)) ;; - esac - fi -done diff --git a/usr/bin/byobu-mondrian b/usr/bin/byobu-mondrian new file mode 100755 index 00000000..a967fea6 --- /dev/null +++ b/usr/bin/byobu-mondrian @@ -0,0 +1,96 @@ +#!/bin/bash +# +# byobu-mondrian: randomly generate some Modrian art in tmux +# +# 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 . + +trap "tput reset; exit 0" EXIT HUP INT QUIT TERM KILL ILL TRAP ABRT BUS FPE USR1 SEGV USR2 PIPE ALRM + +# Special mode, color the screen +if [ "$1" = "color" ] && [ -n "$2" ]; then + i=0 + out= + tput setab "$2" + tput setaf "$2" + count=$(stty size | awk '{print $1*$2}') + while [ $i -lt $count ]; do + out="$out " + i=$((i+1)) + done + printf "$out" + head -n1 + exit 0 +fi + +get_random_pane() { + local panes=$(tmux list-panes | wc -l) + r=$((RANDOM % 4)) + while [ $r = "$LAST_PANE" ]; do + r=$((RANDOM % 4)) + done + LAST_PANE="$r" + echo "$r" +} + +red_color=196 +yellow_color=226 +blue_color=57 +white_color=231 + +# Get number of splits +[ -n "$1" ] && TOTAL_SPLITS=$1 || TOTAL_SPLITS=$((RANDOM % 33 + 7)) + +while true; do + # Choose 1 red, 1 yellow, 1 blue + nums=$(rand -N 3 -M $TOTAL_SPLITS -u) + red=$((RANDOM % TOTAL_SPLITS + 4)) + while [ $red -ge $TOTAL_SPLITS ]; do + red=$((RANDOM % TOTAL_SPLITS + 4)) + done + yellow=$((RANDOM % TOTAL_SPLITS + 4)) + while [ "$yellow" = "$red" ] || [ $yellow -ge $TOTAL_SPLITS ]; do + yellow=$((RANDOM % TOTAL_SPLITS + 4)) + done + blue=$((RANDOM % TOTAL_SPLITS + 4)) + while [ "$blue" = "$yellow" ] || [ "$blue" = "$red" ] || [ $blue -ge $TOTAL_SPLITS ]; do + blue=$((RANDOM % TOTAL_SPLITS + 4)) + done + echo "$red $yellow $blue" > /tmp/out + # Create some splits + tmux new-window -n mondrian "byobu-mondrian color $white_color" + tmux set-option -g pane-active-border-bg default + tmux set-option -g pane-active-border-fg default + for i in $(seq 0 $((TOTAL_SPLITS-1))); do + case $i in + $red) color=$red_color ;; + $yellow) color=$yellow_color ;; + $blue) color=$blue_color ;; + *) color=$white_color ;; + esac + CMD="byobu-mondrian color $color" + [ "$((RANDOM % 2))" = "0" ] && SPLIT="-v" || SPLIT="-h" + if ! tmux split-window $SPLIT -t $(get_random_pane) "$CMD" ; then + case "$i" in + $red) red=$((red+1)) ;; + $yellow) yellow=$((yellow+1)) ;; + $blue) blue=$((blue+1)) ;; + esac + fi + done + sleep 10 + tmux kill-window -t "mondrian" +done