|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -if [ "$#" -ne 3 ]; then |
| 3 | +if [ "$#" -lt 3 ]; then |
4 | 4 | echo -e "\e[32mLet's create a new web app you can start with the app launcher.\n\e[0m" |
5 | 5 | APP_NAME=$(gum input --prompt "Name> " --placeholder "My favorite web app") |
6 | 6 | APP_URL=$(gum input --prompt "URL> " --placeholder "https://example.com") |
7 | | - ICON_URL=$(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com (must use PNG!)") |
| 7 | + ICON_REF=$(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com (must use PNG!)") |
| 8 | + CUSTOM_EXEC="" |
| 9 | + MIME_TYPES="" |
| 10 | + INTERACTIVE_MODE=true |
8 | 11 | else |
9 | 12 | APP_NAME="$1" |
10 | 13 | APP_URL="$2" |
11 | | - ICON_URL="$3" |
| 14 | + ICON_REF="$3" |
| 15 | + CUSTOM_EXEC="$4" # Optional custom exec command |
| 16 | + MIME_TYPES="$5" # Optional mime types |
| 17 | + INTERACTIVE_MODE=false |
12 | 18 | fi |
13 | 19 |
|
14 | | -if [[ -z "$APP_NAME" || -z "$APP_URL" || -z "$ICON_URL" ]]; then |
| 20 | +# Ensure valid execution |
| 21 | +if [[ -z "$APP_NAME" || -z "$APP_URL" || -z "$ICON_REF" ]]; then |
15 | 22 | echo "You must set app name, app URL, and icon URL!" |
16 | 23 | exit 1 |
17 | 24 | fi |
18 | 25 |
|
19 | | -ICON_DIR="$HOME/.local/share/applications/icons" |
20 | | -DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop" |
21 | | -ICON_PATH="$ICON_DIR/$APP_NAME.png" |
22 | | - |
23 | | -mkdir -p "$ICON_DIR" |
| 26 | +# Refer to local icon or fetch remotely from URL |
| 27 | +if [[ $ICON_REF =~ ^https?:// ]]; then |
| 28 | + if curl -sL -o "$ICON_PATH" "$ICON_REF"; then |
| 29 | + ICON_PATH="$ICON_DIR/$APP_NAME.png" |
| 30 | + else |
| 31 | + echo "Error: Failed to download icon." |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | +else |
| 35 | + ICON_PATH="$HOME/.local/share/applications/icons/$ICON_REF" |
| 36 | +fi |
24 | 37 |
|
25 | | -if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then |
26 | | - echo "Error: Failed to download icon." |
27 | | - return 1 |
| 38 | +# Use custom exec if provided, otherwise default behavior |
| 39 | +if [[ -n $CUSTOM_EXEC ]]; then |
| 40 | + EXEC_COMMAND="$CUSTOM_EXEC" |
| 41 | +else |
| 42 | + EXEC_COMMAND="google-chrome-stable --new-window --ozone-platform=wayland --app=$APP_URL --name=$APP_NAME --class=$APP_NAME" |
28 | 43 | fi |
29 | 44 |
|
| 45 | +# Create application .desktop file |
| 46 | +DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop" |
| 47 | + |
30 | 48 | cat >"$DESKTOP_FILE" <<EOF |
31 | 49 | [Desktop Entry] |
32 | 50 | Version=1.0 |
33 | 51 | Name=$APP_NAME |
34 | 52 | Comment=$APP_NAME |
35 | | -Exec=google-chrome-stable --new-window --ozone-platform=wayland --app="$APP_URL" --name="$APP_NAME" --class="$APP_NAME" |
| 53 | +Exec=$EXEC_COMMAND |
36 | 54 | Terminal=false |
37 | 55 | Type=Application |
38 | 56 | Icon=$ICON_PATH |
39 | 57 | StartupNotify=true |
40 | 58 | EOF |
41 | 59 |
|
| 60 | +# Add mime types if provided |
| 61 | +if [[ -n $MIME_TYPES ]]; then |
| 62 | + echo "MimeType=$MIME_TYPES" >>"$DESKTOP_FILE" |
| 63 | +fi |
| 64 | + |
42 | 65 | chmod +x "$DESKTOP_FILE" |
43 | 66 |
|
44 | | -if [ "$#" -ne 3 ]; then |
| 67 | +if [[ $INTERACTIVE_MODE == true ]]; then |
45 | 68 | echo -e "You can now find $APP_NAME using the app launcher (SUPER + SPACE)\n" |
46 | 69 | fi |
0 commit comments