add xdg-mime-default.sh
authorAndrew Lorimer <andrew@lorimer.id.au>
Thu, 14 Mar 2024 06:01:27 +0000 (17:01 +1100)
committerAndrew Lorimer <andrew@lorimer.id.au>
Thu, 14 Mar 2024 06:01:27 +0000 (17:01 +1100)
xdg-mime-default.sh [new file with mode: 0755]
diff --git a/xdg-mime-default.sh b/xdg-mime-default.sh
new file mode 100755 (executable)
index 0000000..84263e5
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+# From https://blog.hexadust.net/xdg-open-setting-default-handler-for-supported-mime-types
+D=$1
+if test -z "$D"; then
+ find /usr/share/applications/ ~/.local/share/applications/ -name '*.desktop' | while read DF; do
+        D=`basename "$DF"`
+      echo $D
+     cat "$DF" | grep MimeType | cut -f2 -d= | tr ';' "\n" | grep -v '^$' | while read M; do
+         echo -ne "\t$M current: "
+            xdg-mime query default "$M"
+     done
+        echo
+    done
+fi
+if test -n "$D"; then
+ find /usr/share/applications/ ~/.local/share/applications/ -name "$D" | while read DF; do
+       cat "$DF" | grep MimeType | cut -f2 -d= | tr ';' "\n" | grep -v '^$' | while read M; do
+         echo "Using $D for $M"
+          xdg-mime default "$D" "$M"
+      done
+    done
+fi