-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsimulator
executable file
·55 lines (48 loc) · 1.33 KB
/
simulator
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
#!/usr/bin/env bash
# tmex 1.0.10
set -euo pipefail
function rand() {
shuf -i"1-$1" -n1 | tr -d '[:space:]'
}
function sizing() {
local sizes='' multi=FALSE leading=''
if (( $( rand 4 ) == 1 )); then
multi=TRUE
fi
for (( idx = "$( rand "$1" )"; idx; idx-- )); do
if [[ "${multi}" == TRUE ]]; then
leading=''; (( $( rand 3 ) == 1 )) && leading='.'
sizes+="${leading}$( rand 19 )."
else
sizes+="$( rand 9 )"
fi
done
echo "{${sizes}}"
}
function randlayout() {
local n="$1" layout='' idx=0 multi=FALSE leading='' panes=0 sizing=''
if (( $( rand 4 ) == 1 )); then
multi=TRUE
fi
for (( idx = "$( rand "${n}" )"; idx; idx-- )); do
if (( n > 2 && $( rand 4 ) == 1 )); then
layout+="[$( randlayout "$(( n / 2 ))" )]"
elif [[ "${multi}" == TRUE ]]; then
panes="$( rand 19 )"
leading=''; (( $( rand 3 ) == 1 )) && leading='.'
sizing=''; (( $( rand 4 ) == 1 )) && sizing="$( sizing "${panes}" )"
layout+="${leading}${panes}.${sizing}"
else
panes="$( rand 9 )"
sizing=''; (( $( rand 4 ) == 1 )) && sizing="$( sizing "${panes}" )"
layout+="${panes}${sizing}"
fi
done
echo "${layout//../.}"
}
function main() {
local layout
layout="$( randlayout "${1:-8}" )"
tmex "LAYOUT=${layout}" --simulator --shellless --layout="${layout}"
}
main "$@"