-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtui
executable file
·118 lines (104 loc) · 2.94 KB
/
tui
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
#! /usr/bin/env bash
# Turn off command echo
set +x
# Function to load project name and executables from .cabal file
load_project_info_from_cabal() {
# Find the .cabal file in the current directory
local cabal_file=$(find . -maxdepth 1 -name "*.cabal")
if [[ -z "$cabal_file" ]]; then
echo "No .cabal file found in the current directory."
exit 1
fi
# Parse the .cabal file for the project name
local project_name=$(grep "^name:" "$cabal_file" | awk '{print $2}')
if [[ -z "$project_name" ]]; then
echo "No project name found in the .cabal file."
exit 1
fi
export PROJECT_NAME="$project_name"
# Initialize the executables array
declare -gA executables
# Parse the .cabal file for executable names
while IFS= read -r line; do
local exe_name=$(echo "$line" | awk '{print $2}')
executables["$exe_name"]=""
done < <(grep "^executable" "$cabal_file")
}
# Function to build a specific executable
build_exe() {
local exeName=$1
echo "Building $exeName..."
nix build .#$PROJECT_NAME:exe:$exeName --show-trace --accept-flake-config
}
# Function to build all executables
build_all_exes() {
echo "Building all executables..."
for exe in "${!executables[@]}"; do
build_exe "$exe"
done
}
# Function to run a specific executable, optionally with arguments
run_exe() {
local exeName=$1
shift # Remove the first argument, which is the executable name
local args="$@"
echo "Running $exeName with arguments: $args"
./result/bin/$exeName $args
}
# Function to collect garbage
collect_garbage() {
echo "Collecting garbage..."
nix-collect-garbage -d
echo "Garbage collection complete."
}
# Function to update the flake
update_flake() {
echo "Updating flake..."
nix flake update
echo "Flake update complete."
}
# Load project info from the .cabal file
load_project_info_from_cabal
# Check for command-line arguments
if [[ "$1" == "--build-all" ]]; then
build_all_exes
exit 0
fi
# Main menu
PS3='Please enter your choice: '
options=("Build all executables" "Build and Run specific executable" "Collect Garbage" "Update Flake" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Build all executables")
build_all_exes
break
;;
"Build and Run specific executable")
echo "Select an executable to build and run:"
select exe in "${!executables[@]}"
do
prompt=${executables[$exe]}
if [[ -n $prompt ]]; then
echo "$prompt"
read additional_args
fi
build_exe $exe
run_exe $exe $additional_args
break 2
done
;;
"Collect Garbage")
collect_garbage
break
;;
"Update Flake")
update_flake
break
;;
"Quit")
break
;;
*) echo "Invalid option $REPLY";;
esac
done