aboutsummaryrefslogtreecommitdiff
path: root/generate-multimc-desktop-files
blob: 9c86270bc7248662610883def5282713e0c176fa (plain)
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
#!/bin/bash

echo "Deleting old .desktop files"
rm ~/.local/share/applications/multimc-*.desktop

echo "Seeking instances"


create_desktop_file() {
    cat <<EOF > "$HOME/.local/share/applications/multimc-$2-$3.desktop"
[Desktop Entry]
Name=MultiMC: $1
Type=Application
Categories=Game
StartupWMClass=multimc
Terminal=false
Comment=Open MultiMC Instance
GenericName=Minecraft
Exec=$(which "$2") -l "$3"
EOF
}

check_instance() {
  if [[ (-d "$1") && (-f "$1/instance.cfg") ]]; then
    echo "Scanning $1"
    instanceid="$(basename -- "$1")"
    name="$instanceid"
    while IFS="=" read -r key value; do
      case "$key" in
      name)
        echo "Instance Name: $value"
        name="$value"
        ;;
      esac
    done <"$1/instance.cfg"
    create_desktop_file "$name" "$2" "$instanceid"
  fi
}

for instdir in ~/.local/share/multimc/instances/*; do
    check_instance "$instdir" multimc
done
for instdir in ~/.local/share/PolyMC/instances/*; do
    check_instance "$instdir" polymc
done