Skip to content

Instantly share code, notes, and snippets.

@danielpza
Created September 25, 2019 09:19
Show Gist options
  • Save danielpza/b226d0984f3ba1d60539dbd5b2b65fe4 to your computer and use it in GitHub Desktop.
Save danielpza/b226d0984f3ba1d60539dbd5b2b65fe4 to your computer and use it in GitHub Desktop.
Set default application for all available mimetype on linux
#!/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