Created
September 25, 2019 09:19
-
-
Save danielpza/b226d0984f3ba1d60539dbd5b2b65fe4 to your computer and use it in GitHub Desktop.
Set default application for all available mimetype on linux
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
#!/usr/bin/env bash | |
# Usage: set-default "app.desktop" | |
# see https://unix.stackexchange.com/a/361705/233294 | |
set_default() { | |
d=$1 | |
for m in $(grep MimeType "$d" | cut -d= -f2 | tr ";" " "); do | |
echo xdg-mime default "$d" "$m" | |
xdg-mime default "$d" "$m" | |
done | |
} | |
if [[ -f "$(echo $XDG_DATA_HOME || "~/.local/share")/$1" ]]; then | |
set_default "$(echo $XDG_DATA_HOME || "~/.local/share")/$1" | |
elif [[ -f "/usr/share/applications/$1" ]]; then | |
set_default "/usr/share/applications/$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment