-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.sh
165 lines (135 loc) · 3.73 KB
/
ui.sh
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
# Function to execute the binary
execute_binary() {
local bin_dir="build/bin/$1"
if [[ ! -d "$bin_dir" ]]; then
echo "Directory $bin_dir does not exist!"
exit 1
fi
local bin_file
for file in "$bin_dir"/*; do
if [[ ! "$file" =~ \. ]]; then
bin_file="$file"
break
fi
done
if [[ -z "$bin_file" ]]; then
echo "No executable file found in $bin_dir"
exit 1
fi
./"$bin_file"
}
# Array to store project names
declare -a project_names
# Function to get project names from premake.lua
get_projects() {
project_names=()
local FILE="premake.lua"
if [[ ! -f "$FILE" ]]; then
echo "File $FILE not found!"
exit 1
fi
local -a TEMP_PROJECTS=()
local -a TEMP_KINDS=()
while IFS= read -r line; do
if [[ $line =~ project\ \"([^\"]+)\" ]]; then
TEMP_PROJECTS+=("${BASH_REMATCH[1]}")
fi
if [[ $line =~ kind\ \"([^\"]+)\" ]]; then
TEMP_KINDS+=("${BASH_REMATCH[1]}")
fi
done < "$FILE"
for ((i=0; i<${#TEMP_PROJECTS[@]}; i++)); do
if [[ "${TEMP_KINDS[i]}" != "None" ]]; then
project_names+=("${TEMP_PROJECTS[i]}")
fi
done
}
MENU_MODE="release"
MENU_MODE_TURN="debug"
# Function to display the menu and handle project selection
menu() {
echo "Make menu: ($MENU_MODE only)"
project_names=()
get_projects
for i in "${!project_names[@]}"; do
echo "$i - ${project_names[i]}"
done
echo "${#project_names[@]} - Exit"
echo "$((${#project_names[@]} + 1)) - change to $MENU_MODE_TURN"
read -p "Choose an option: " project_chosen
if [[ "$project_chosen" -ge $((${#project_names[@]} + 2)) || "$project_chosen" -lt 0 ]]; then
exit 0
fi
if [[ "$project_chosen" -eq "" ]]; then
local T="$MENU_MODE"
MENU_MODE="$MENU_MODE_TURN"
MENU_MODE_TURN="$T"
return 1
fi
if [[ "$project_chosen" -eq $((${#project_names[@]} + 1)) ]]; then
local T="$MENU_MODE"
MENU_MODE="$MENU_MODE_TURN"
MENU_MODE_TURN="$T"
return 1
fi
cd build || exit 1
make config=$MENU_MODE "${project_names[project_chosen]}"
cd ..
tmux send-keys -t my_session:0.0 C-c
sleep 2
tmux send-keys -t my_session:0.0 "bash $0 --compiler" C-m
}
# Function to handle compiler actions
compiler() {
clear
echo "Enter mode"
echo "1) Release"
echo "2) Debug"
echo "*) ---"
read -p "mode: " mode
case "$mode" in
1)
mode="release"
;;
2)
mode="debug"
;;
*)
mode="all"
;;
esac
if [[ "$mode" == "release" ]]; then
execute_binary Release
elif [[ "$mode" == "debug" ]]; then
execute_binary Debug
fi
}
# Main function to handle tmux session creation and management
main() {
local SESSION="my_session"
tmux has-session -t $SESSION 2>/dev/null && tmux kill-session -t $SESSION
tmux new-session -d -s $SESSION -n main || { echo "Error creating tmux session."; exit 1; }
tmux split-window -h -t $SESSION:0 || { echo "Error splitting tmux window."; exit 1; }
sleep 1
tmux send-keys -t "$SESSION":0.1 "bash $0 --menu" C-m || { echo "Error sending command to tmux session."; exit 1; }
tmux send-keys -t "$SESSION":0.0 "bash $0 --compiler" C-m || { echo "Error sending command to tmux session."; exit 1; }
tmux attach-session -t $SESSION
}
# Argument handling
case "$1" in
--menu)
while true; do
clear
menu
done
;;
--compiler)
while true; do
compiler
done
;;
*)
main
;;
esac