-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhollywood
executable file
·150 lines (123 loc) · 3.67 KB
/
hollywood
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
#
# This is the version of hollywood for MacOSX. Suggest improvements for this version at github.com/real-aazam/hollywood
# hollywood originally created by Dustin Kirkland <[email protected]> https://github.com/dustinkirkland/hollywood
#
# hollywood: create a hollywood suitable consoles of tech geekery - Dustin Kirkland <[email protected]>
#
# Arguments:
# -d|--delay DELAY The delay in seconds before rearranging splits (default=10s)
# -s|--splits SPLITS The number of splits to divide your screen
# -e|--expand Expand terminal screen on script startup (0 or 1, default = 1)
# -h|--help Print help message
PKG="hollywood"
trap "pkill -f hollywood; exit 0" INT
Help()
{
# Display Help
echo "hollywood (v1.0 for mac osx): create a hollywood suitable consoles of tech geekery"
echo "hollywood was originally created by Dustin Kirkland"
echo ""
echo "This is the version for MacOSX. Suggest improvements for this version at github.com/real-aazam/hollywood"
echo ""
echo "usage: hollywood [-d DELAY] [-s SPLITS] [-e EXPAND]"
echo ""
echo "Optional arguments:"
echo " -d|--delay DELAY : The delay in seconds before rearranging splits (default=10)"
echo " -s|--splits SPLITS : The number of splits to divide your screen"
echo " -e|--expand EXPAND : Expand terminal screen on script startup (0 or 1, default = 1)"
echo " -h|--help : Print this help message"
echo ""
echo ""
echo "Press the Control and C keys to stop the script. If you manually closed the terminal screen, then background tasks may still be running. In this case, simply run hollywood again and press the Control and C keys to stop the script and kill background tasks."
echo ""
}
spin_up() {
local w=
local panes=
local splits=
local pane=
local dir="v"
local split=1
sleep 0.5
for w in $(ls "$WIDGET_DIR" | sort -R); do
[ "$dir" = "-v" ] && dir="-h" || dir="-v"
panes=$(tmux list-panes -t $PKG 2>/dev/null)
# Allow for failed widgets
splits=$(echo "$panes" | wc -l)
pane=$((RANDOM % $splits))
tmux split-window $dir -t ${PKG}.$pane "nice -n 19 $WIDGET_DIR/$w" >/dev/null 2>&1
sleep 0.2
split=$((split+1))
if [ $split -ge $SPLITS ]; then
break
fi
done
}
WIDGET_DIR="$(dirname $0)/resources/widgets"
SPLITS=$(ls "$WIDGET_DIR" | wc -l)
DELAY=10
EXPAND=1
WIDGETS_FOUND=0
while [ ! -z "$1" ]; do
case "$1" in
-d|--delay)
DELAY="$2"
shift 2
;;
-s|--splits)
SPLITS="$2"
shift 2
;;
-e|--expand)
EXPAND="$2"
shift 2
;;
-w|--widgets)
WIDGETS_FOUND="$2"
shift 2
;;
-h|--help|*)
# TODO: exec man $PKG
Help
exit
;;
esac
done
widgets_all=$(ls "$WIDGET_DIR/" | sort -R)
if [[ "$WIDGETS_FOUND" == "1" ]]; then printf '%s\n' "${widgets_all[@]}"; exit; fi;
if [[ "$EXPAND" == "1" ]]; then printf "\033[8;99999;99999t"; fi;
widget1=$(ls "$WIDGET_DIR/" | sort -R | head -n1)
arrangements="main-horizontal main-vertical tiled"
if [ -z "$TMUX" ]; then
# Not in a tmux session: start one, with
# byobu if it's found, else with plain tmux
command -v byobu >/dev/null 2>&1
if [ $? -eq 0 ]; then
tmux_launcher=byobu
else
tmux_launcher=tmux
fi
$tmux_launcher new-session -d -s $PKG "/bin/bash"
$tmux_launcher send-keys -t $PKG "$0 $1"
$tmux_launcher send-keys -t $PKG Enter
exec $tmux_launcher attach-session -t $PKG
exit 1
fi
tmux new-window -n $PKG "$WIDGET_DIR/$widget1" \; \
set-option -g pane-active-border-bg "default" \; \
set-option -g pane-active-border-fg "default" >/dev/null 2>&1
spin_up
i=0
while true; do
i=$((i+1))
if [ "$((i % DELAY))" = "0" ]; then
tmux kill-pane -a -t $PKG.bottom-right
spin_up
fi
if [ $(tmux list-panes -t $PKG 2>/dev/null | wc -l) -gt 0 ]; then
sleep 1
continue
fi
exit 0
done