TyOS-Local-Scripts/flatpak_selections

37 lines
1 KiB
Bash

#!/bin/bash
# Directory containing scripts
SCRIPT_DIR="/usr/local/bin/flatpacks"
# Check if the directory exists
if [[ ! -d "$SCRIPT_DIR" ]]; then
echo "Directory $SCRIPT_DIR does not exist."
exit 1
fi
# Get list of scripts
SCRIPTS=($(ls "$SCRIPT_DIR"))
# Check if there are any scripts
if [[ ${#SCRIPTS[@]} -eq 0 ]]; then
whiptail --msgbox "No scripts found in $SCRIPT_DIR" 10 40
exit 0
fi
# Build menu options
MENU_OPTIONS=()
for SCRIPT in "${SCRIPTS[@]}"; do
# Remove underscores and capitalize first letter of each word
DISPLAY_NAME=$(echo "$SCRIPT" | sed 's/_/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')
MENU_OPTIONS+=("Flatpackage" "$DISPLAY_NAME")
done
# Show menu with the new title
SELECTED_SCRIPT=$(whiptail --title "TyOS Flatpak Selections" --menu "Choose a script to run:" 20 60 10 "${MENU_OPTIONS[@]}" 3>&1 1>&2 2>&3)
# Check if a script was selected
if [[ -n "$SELECTED_SCRIPT" ]]; then
bash "$SCRIPT_DIR/$SELECTED_SCRIPT"
else
whiptail --msgbox "No script selected." 10 40
fi