Mitch Effendi 2 ماه پیش
کامیت
56b1d12a7b
3فایلهای تغییر یافته به همراه107 افزوده شده و 0 حذف شده
  1. 0 0
      README.md
  2. 38 0
      programs.json
  3. 69 0
      tui-launcher.sh

+ 0 - 0
README.md


+ 38 - 0
programs.json

@@ -0,0 +1,38 @@
+[
+  {
+    "name": "btm",
+    "command": "btm",
+    "description": "A cross-platform, terminal-based resource monitor.",
+    "emoji": "〽️"
+  },
+  {
+    "name": "btop",
+    "command": "btop",
+    "description": "A resource monitor that shows usage and stats for processor, memory, disks, network and processes.",
+    "emoji": "📈"
+  },
+  {
+    "name": "tut",
+    "command": "tut",
+    "description": "Command line Mastodon client.",
+    "emoji": "🐘"
+  },
+  {
+    "name": "w3m",
+    "command": "w3m",
+    "description": "Command line web browser.",
+    "emoji": "🌎"
+  },
+  {
+    "name": "oterm",
+    "command": "oterm",
+    "description": "A TUI for Ollama.",
+    "emoji": "🦙"
+  },
+  {
+    "name": "aichat",
+    "command": "aichat",
+    "description": "A Rust TUI for chatting with Gemini.",
+    "emoji": "✨"
+  }
+]

+ 69 - 0
tui-launcher.sh

@@ -0,0 +1,69 @@
+#!/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 'Ctrl+D'), $(gum style --bold 'b'), or $(gum style --bold 'ESC') 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