summarylogtreecommitdiffstats
path: root/apply-xdg-patch.sh
blob: 2bb3fbb177959b00e345b1eeb59191db9ef62ca3 (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
#!/bin/sh

add_mime_type() {
  if ! grep -q -E "^MimeType=.*\b${1};" "$2"
  then
    sed -i -E "s#^(MimeType=.*;)\$#\1${1};#" "$2"
  fi
}

# see https://github.com/microsoft/vscode/issues/15741
fix_15741() {
  add_mime_type 'inode/directory' "$1"
}

# see https://github.com/microsoft/vscode/issues/129953#issuecomment-1323778127
fix_129953() {
  sed -i -E 's/"desktopName":\s*"(.+)-url-handler\.desktop"/"desktopName": "\1.desktop"/' "$1"
}

# see https://github.com/microsoft/vscode/issues/214741
fix_214741() {
  add_mime_type 'text/plain' "$1"
}

while read -r file
do
  case "$file" in
    *.desktop)
      fix_214741 "$file"
      fix_15741 "$file"
      echo "patched $file"
      ;;
    */package.json)
      fix_129953 "$file"
      echo "patched $file"
      ;;
    *)
      echo "unexpected file: $file"
  esac
done