#!/bin/bash check_dependencies() { for dep in jq gum figlet lolcat; do if ! command -v "$dep" &> /dev/null; then gum style --foreground 212 "$dep is not installed." if gum confirm "Do you want to install $dep?"; then # Assuming Debian/Ubuntu based system sudo apt-get update && sudo apt-get install -y "$dep" if ! command -v "$dep" &> /dev/null; then gum style --foreground 212 "Failed to install $dep. Please install it manually." exit 1 fi else gum style --foreground 212 "Installation cancelled. Please install $dep to continue." exit 1 fi fi done } check_dependencies # Read the programs from the JSON file PROGRAMS_JSON=$(cat "$(dirname "$0")/programs.json") PROGRAM_NAMES=$(echo "$PROGRAMS_JSON" | jq -r '.[].name') while true; do clear figlet "TUI Launcher" | lolcat gum style --border normal --padding '1 2' --margin 1 "Press $(gum style --bold 'ESC') or $(gum style --bold 'Q') to exit." # Create header HEADER="Icon,Program,Description" # Create rows from JSON ROWS=$(echo "$PROGRAMS_JSON" | jq -r '.[] | [.emoji, .name, .description] | @csv') # Show the gum table CHOICE=$(echo -e "$HEADER\n$ROWS" | gum table --widths=5,20,75) # If the user made a choice if [ -n "$CHOICE" ]; then # Extract the program name from the selected row CHOSEN_NAME=$(echo "$CHOICE" | cut -d',' -f2) if [ -n "$CHOSEN_NAME" ]; then # Get the corresponding command COMMAND_TO_RUN=$(echo "$PROGRAMS_JSON" | jq -r --arg name "$CHOSEN_NAME" '.[] | select(.name == $name) | .command') # Run the command if [ -n "$COMMAND_TO_RUN" ]; then # Clear the screen before launching the program for a cleaner experience clear eval "$COMMAND_TO_RUN" else gum style --foreground 212 "Invalid selection." fi else gum style --foreground 212 "Could not determine selection." fi else gum style --foreground 212 "Exiting..." break fi gum style --border normal --padding '0 1' --margin 1 "[↑/k] Up | [↓/j] Down | [Enter] Select" done