-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set default text/plain editor to something not LibreOffice
Debian does not define default application, so the choice is a bit random (in practice - lexicographical). For text/plain, it hits LibreOffice, which is very unfriendly for text/plain. Choose something that is not libreoffice instead. Fedora does define gedit as default editor, but xdg-open doesn't handle mimeapps.list, it only looks for defaults.list file. Add a symlink to fix this (but not on Ubuntu, which ships the symlink via desktop-file-utils package). Re-calculate the choice on package update too, if the currently selected editor doesn't exist anymore (happens for example when org.gnome.gedit is replaced with org.gnome.TextEditor). Fixes QubesOS/qubes-issues#8385
- Loading branch information
Showing
7 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/sh | ||
|
||
text_plain_app=$(xdg-mime query default text/plain) | ||
|
||
if [ -n "$text_plain_app" ] && | ||
[ -e "/usr/share/applications/$text_plain_app" ] && | ||
[ "$text_plain_app" != "libreoffice-writer.desktop" ]; then | ||
# not set to libreoffice, nothing to do | ||
exit 0 | ||
fi | ||
|
||
text_plain_apps=$( | ||
grep -rl '^MimeType=.*text/plain;' "/usr/share/applications" | | ||
LC_ALL=C sort | | ||
while read -r app; do | ||
app_name=$(basename "$app") | ||
if grep -q '^Terminal=[tT]' "$app"; then | ||
continue | ||
elif [ "$app_name" = "libreoffice-writer.desktop" ]; then | ||
continue | ||
fi | ||
printf "%s" "$app_name;" | ||
done | ||
) | ||
|
||
if [ -z "$text_plain_apps" ]; then | ||
echo "No application handle text/plain, do not set default" >&2 | ||
exit 0 | ||
fi | ||
|
||
mimeapps_file="/usr/share/applications/mimeapps.list" | ||
touch "$mimeapps_file" | ||
awk -v apps="$text_plain_apps" ' | ||
/^\[/ { | ||
if (indefault && !added) { | ||
print "text/plain=" apps | ||
added=1 | ||
} | ||
indefault=0 | ||
} | ||
/^\[Default Applications\]/ { indefault=1 } | ||
/^text\/plain=/ { | ||
if (indefault) { print "text/plain=" apps; added=1 } | ||
else { print } | ||
next | ||
} | ||
/./ { print } | ||
END { | ||
if (!added) { | ||
if (!indefault) { print "[Default Applications]" } | ||
print "text/plain=" apps | ||
} | ||
} | ||
' < "$mimeapps_file" > "$mimeapps_file.new" && \ | ||
mv "$mimeapps_file.new" "$mimeapps_file" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters