-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuforge
More file actions
executable file
·307 lines (270 loc) · 12 KB
/
Copy pathmenuforge
File metadata and controls
executable file
·307 lines (270 loc) · 12 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
# MenuForge v1.2.0
# Technical Management System for Linux Desktop Entries.
# Developed by SahooShuvranshu & Crystal Studio Labs
if [ -z "$BASH_VERSION" ]; then
echo "Error: This script must be run with bash."
exit 1
fi
# ---------------------------------------------------------
# Modular Integration
# ---------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LIB_PATH="$HOME/.local/bin/menuforge-lib.sh"
[ -f "$LIB_PATH" ] || LIB_PATH="$SCRIPT_DIR/menuforge-lib.sh"
[ -f "$LIB_PATH" ] || LIB_PATH="./menuforge-lib.sh"
if [ -f "$LIB_PATH" ]; then
source "$LIB_PATH"
else
echo "Architecture Error: Core library not found. System integrity compromised."
exit 1
fi
# Validation: Ensure TUI environment is functional.
command -v gum &> /dev/null || { echo "Runtime Error: 'gum' is missing. Please run the installer."; exit 1; }
APP_DIR_USER="$HOME/.local/share/applications"
# ---------------------------------------------------------
# UI Framework Logic
# ---------------------------------------------------------
step_header() { gum style --foreground "$PRIMARY" --bold " ❯ $2 "; }
instruction_box() { gum style --border normal --border-foreground "$SECONDARY" --padding "1 2" --margin "1 0" --width 58 "$1"; }
check_dep_status() {
if command -v "$1" &> /dev/null; then
echo -e " [✔] $1 - INTEGRATED"
else
echo -e " [✘] $1 - NOT DETECTED"
fi
}
refresh_menu() {
# Propagates XDG changes to active desktop environments.
for tool in walker rofi wofi; do command -v "$tool" &> /dev/null && pkill -HUP "$tool" 2>/dev/null; done
}
# --- Logic Layer: Helpers ---
manage_dependencies() {
banner "INFRASTRUCTURE" "Dependency Monitoring"
step_header "INFRA" "STATUS CHECK"
instruction_box "Verifying critical optimization layers. Selection of 'Install' will trigger a modular deployment process."
echo ""
check_dep_status "gamemoderun"
check_dep_status "mangohud"
check_dep_status "gamescope"
[ "$HAS_NVIDIA" = true ] && check_dep_status "prime-run"
check_dep_status "wine"
echo ""
DEP_ACTION=$(gum choose "INSTALL_ALL_MISSING" "BACK_TO_CORE")
if [ "$DEP_ACTION" == "INSTALL_ALL_MISSING" ]; then
if command -v xdg-terminal-exec &> /dev/null; then
xdg-terminal-exec menuforge-dep-installer
else
for term in alacritty kitty foot ghostty gnome-terminal konsole xfce4-terminal st; do
if command -v "$term" &> /dev/null; then
"$term" -e menuforge-dep-installer &
break
fi
done
fi
gum style --foreground "$PRIMARY" "Deployment process initialized in separate terminal."
sleep 2
fi
}
create_shortcut() {
banner "DEPLOYMENT" "Target Acquisition"
step_header "01" "APPLICATION NAME"
instruction_box "EXPLANATION: Enter the professional display name for your application. This name will identify the software in your system menu and application launcher."
NAME=$(gum input --placeholder "INPUT NAME (e.g. Elden Ring)")
[ -z "$NAME" ] && return
banner "DEPLOYMENT" "Target Acquisition"
step_header "02" "TARGET ACQUISITION"
instruction_box "EXPLANATION: Locate the primary execution file. MenuForge supports native Linux binaries, shell scripts, and Windows (.exe) files via the Wine compatibility layer."
if gum confirm "Open high-fidelity file picker to select target?"; then
EXEC_PATH=$(gum file "$HOME" --header "SELECT EXECUTABLE")
else
EXEC_PATH=$(gum input --placeholder "Manually input full path to binary")
fi
[ -z "$EXEC_PATH" ] && return
[ -f "$EXEC_PATH" ] || { gum style --foreground 1 "Error: File not found at the specified location."; sleep 1; return; }
IS_EXE=false
[[ "$EXEC_PATH" == *.exe ]] && IS_EXE=true
banner "DEPLOYMENT" "Visual Assets"
step_header "03" "VISUAL ASSET MAPPING"
instruction_box "EXPLANATION: Assign a visual identity to your shortcut. You may choose a custom .png or .svg file, or skip to allow the desktop environment to assign a generic icon."
if gum confirm "Open file picker to select custom asset (Icon)?"; then
ICON_PATH=$(gum file "$(dirname "$EXEC_PATH")" --header "SELECT ICON ASSET")
else
ICON_PATH=""
fi
banner "DEPLOYMENT" "Display Strategy"
step_header "04" "DISPLAY STRATEGY"
instruction_box "EXPLANATION: Define the resolution layer for this application. Virtual Fullscreen (Gamescope) is highly recommended for modern gaming to handle scaling and resolution virtualization."
RES_CHOICE=$(gum choose --header "Select primary display mode" \
"Keep System Default (Recommended)" \
"Force 720p (Performance focus)" \
"Force LowRes (800x600 Optimization)" \
"Virtual Fullscreen (Gamescope f-mode)" \
"Back to Menu")
[[ -z "$RES_CHOICE" || "$RES_CHOICE" == "Back to Menu" ]] && return
case "$RES_CHOICE" in
"Force 720p (Performance focus)") RES_CMD="gamescope -w 1280 -h 720 -r 60 -- " ;;
"Force LowRes (800x600 Optimization)") RES_CMD="gamescope -w 800 -h 600 -r 60 -- " ;;
"Virtual Fullscreen (Gamescope f-mode)") RES_CMD="gamescope -f -w 1366 -h 768 -- " ;;
*) RES_CMD="" ;;
esac
banner "DEPLOYMENT" "Optimization"
step_header "05" "PERFORMANCE HOOKS"
instruction_box "EXPLANATION: Inject high-performance optimization layers.
- GAMEMODE: Linux daemon to optimize OS performance.
- MANGOHUD: Real-time hardware telemetry and FPS counter.
- PRIME-RUN: Directs execution to the dedicated NVIDIA GPU.
Use [SPACE] to select MULTIPLE, then [ENTER] to confirm."
OPTS=("GameMode" "MangoHud")
[ "$HAS_NVIDIA" = true ] && OPTS+=("NVIDIA Prime Run")
OPTS+=("None / Skip this step")
EXTRAS=$(gum choose --no-limit --header "Select performance optimizations" "${OPTS[@]}")
[[ "$EXTRAS" == *"None / Skip"* ]] && EXTRAS=""
FINAL_CMD="$RES_CMD"
[[ "$EXTRAS" == *"GameMode"* ]] && FINAL_CMD="gamemoderun $FINAL_CMD"
[[ "$EXTRAS" == *"MangoHud"* ]] && FINAL_CMD="mangohud $FINAL_CMD"
[[ "$EXTRAS" == *"NVIDIA Prime Run"* ]] && FINAL_CMD="prime-run $FINAL_CMD"
[ "$IS_EXE" = true ] && FINAL_CMD="$FINAL_CMD wine"
FINAL_CMD="$FINAL_CMD \"$EXEC_PATH\""
banner "DEPLOYMENT" "Metadata"
step_header "06" "METADATA CATEGORIZATION"
instruction_box "EXPLANATION: Classify your application. This determines where the software is indexed within your desktop environment's menu system (e.g., GNOME Activities, KDE Kickoff)."
MAIN_CAT=$(gum choose "Games" "Applications" "Utility" "Multimedia" "Development" "Internet" "Office")
[ -z "$MAIN_CAT" ] && return
case "$MAIN_CAT" in
"Games")
SUB_CAT=$(gum choose --no-limit "Game" "ActionGame" "AdventureGame" "RolePlaying" "StrategyGame" "Simulation" "SportsGame" "ArcadeGame")
CATEGORIES=$(echo "$SUB_CAT" | tr '\n' ';')
;;
"Applications")
SUB_CAT=$(gum choose --no-limit "Settings" "System" "Graphics" "Network")
CATEGORIES=$(echo "$SUB_CAT" | tr '\n' ';')
;;
"Multimedia")
SUB_CAT=$(gum choose --no-limit "Audio" "Video" "AudioVideo" "Player" "Recorder")
CATEGORIES=$(echo "$SUB_CAT" | tr '\n' ';')
;;
"Development")
SUB_CAT=$(gum choose --no-limit "IDE" "Debugger" "Profiling" "WebDevelopment")
CATEGORIES=$(echo "$SUB_CAT" | tr '\n' ';')
;;
*)
CATEGORIES="$MAIN_CAT;"
;;
esac
banner "DEPLOYMENT" "Terminal"
step_header "07" "TERMINAL EMULATION"
instruction_box "EXPLANATION: Determine if this application requires a persistent console window during execution. This is essential for terminal-based tools (TUIs/CLIs)."
TERM_REQ=$(gum confirm "Does this application require a terminal window?" && echo "true" || echo "false")
banner "REVIEW" "Final Verification"
SAFE_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/_/g')
DEST="$APP_DIR_USER/menuforge_$SAFE_NAME.desktop"
gum style --foreground "$PRIMARY" "FORGE TARGET: $NAME"
gum style --foreground "$PRIMARY" "COMMAND: $FINAL_CMD"
echo "DEPLOYMENT PATH: $DEST"
echo ""
if gum confirm "INITIALIZE SYSTEM DEPLOYMENT?"; then
banner "FORGING"
gum spin --spinner hammer --title "Forging desktop entry..." -- sleep 1
cat <<EOF > "$DEST"
[Desktop Entry]
Name=$NAME
Exec=$FINAL_CMD
Path=$(dirname "$EXEC_PATH")
Icon=$ICON_PATH
Terminal=$TERM_REQ
Type=Application
Categories=$CATEGORIES
X-Created-By=MenuForge
EOF
[ $? -eq 0 ] || error_exit "Failed to write desktop entry."
chmod +x "$DEST" &> /dev/null
refresh_menu &> /dev/null
banner "SUCCESS"
gum style --foreground 10 --bold "✓ DEPLOYMENT SUCCESSFUL"
echo ""
gum style --faint "Managed entry created at: $DEST"
sleep 2
fi
}
remove_shortcut() {
banner "MANAGEMENT" "Link Purge"
mapfile -t FILES < <(grep -l "X-Created-By=MenuForge" "$APP_DIR_USER"/menuforge_*.desktop 2>/dev/null)
if [ ${#FILES[@]} -eq 0 ]; then
gum style --foreground "$PRIMARY" "No managed links found."
sleep 1; return
fi
MENU_ENTRIES=()
for f in "${FILES[@]}"; do
dname=$(grep "^Name=" "$f" | cut -d'=' -f2)
fname=$(basename "$f")
MENU_ENTRIES+=("$dname ($fname)")
done
SELECTED=$(gum choose "${MENU_ENTRIES[@]}" "Back")
[[ -z "$SELECTED" || "$SELECTED" == "Back" ]] && return
TARGET_FNAME=$(echo "$SELECTED" | sed 's/.*(\(.*\))/\1/')
TARGET_FILE="$APP_DIR_USER/$TARGET_FNAME"
if gum confirm "Permanently remove $SELECTED?"; then
rm "$TARGET_FILE" &> /dev/null
refresh_menu &> /dev/null
gum style --foreground 10 "✓ Purged."
sleep 1
fi
}
# ---------------------------------------------------------
# Entry Point: System Controller
# Orchestrates high-level system operations via TUI loop.
# ---------------------------------------------------------
run_tui() {
while true; do
banner "MENUFORGE v1.2.0" "Developed by SahooShuvranshu & Crystal Studio Labs"
gum style --faint " High-Performance Linux Desktop Integration Layer"
echo " ------------------------------------------------------------"
echo ""
ACTION=$(gum choose "ADD_NEW_LINK" "REMOVE_LINK" "MANAGE_DEPENDENCIES" "EXIT")
case "$ACTION" in
"ADD_NEW_LINK") create_shortcut ;;
"REMOVE_LINK") remove_shortcut ;;
"MANAGE_DEPENDENCIES") manage_dependencies ;;
*) banner "EXIT"; gum style --foreground "$PRIMARY" --bold "System Hibernation Initialized. Goodbye."; exit 0 ;;
esac
done
}
case "$1" in
"--doctor")
run_doctor
;;
"--version"|"-v")
echo "MenuForge v1.2.0-Stable"
echo "Developed by SahooShuvranshu & Crystal Studio Labs"
;;
"--help"|"-h")
echo "MenuForge v1.2.0-Stable | Professional Desktop Entry Bridge"
echo "Developed by SahooShuvranshu & Crystal Studio Labs"
echo ""
echo "Usage: menuforge [options]"
echo ""
echo "Modes:"
echo " (no args) Launch the primary interactive TUI controller"
echo " --doctor Conduct a system-wide integrity and dependency audit"
echo ""
echo "Information:"
echo " --version, -v Display system version and authorship credits"
echo " --help, -h Show this comprehensive technical reference"
echo ""
echo "Examples:"
echo " $ menuforge # Initiate the control center"
echo " $ menuforge --doctor # Audit system infrastructure"
echo ""
echo "For advanced usage and library integration, visit:"
echo "https://crystal-studio-labs.github.io/MenuForge/"
;;
"")
run_tui
;;
*)
echo "Error: Unrecognized option '$1'"
echo "Try 'menuforge --help' for more information."
exit 1
;;
esac