#!/usr/bin/env bash #============================================================================== #title : sanemime.sh #description : Resets MIMe configuration to sane defaults in case any shitty # software broke it. #author : hmk #date : 20210620 #version : 0.4 #============================================================================== cp ${HOME}/.config/mimeapps.list ${HOME}/.config/mimeapps.list.bak BROWSER=/usr/share/applications/firefox.desktop EMAIL=${HOME}/.local/share/applications/neomutt.desktop IMAGE_VIEWER=/usr/share/applications/sxiv.desktop VIDEO_VIEWER=/usr/share/applications/mpv.desktop PDF_VIEWER=/usr/share/applications/org.pwmt.zathura-pdf-mupdf.desktop FILE_MANAGER=/usr/share/applications/thunar.desktop TEXT_EDITOR=/usr/share/applications/leafpad.desktop MSTEAMS=${HOME}/.local/share/applications/teams.desktop TS3=${HOME}/.local/share/applications/teamspeak.desktop ZOOM=${HOME}/.local/share/applications/zoom.desktop # Set default browser BROWSER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${BROWSER}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${BROWSER}) for type in ${types[@]}; do echo "Setting ${type} to ${BROWSER_NAME}" xdg-mime default $(basename ${BROWSER}) ${type} done # Set default E-Mail client EMAIL_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${EMAIL}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${EMAIL}) for type in ${types[@]}; do echo "Setting ${type} to ${EMAIL_NAME}" xdg-mime default $(basename ${EMAIL}) ${type} done # Set default file manager FILE_MANAGER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${FILE_MANAGER}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${FILE_MANAGER}) for type in ${types[@]}; do echo "Setting ${type} to ${FILE_MANAGER_NAME}" xdg-mime default $(basename ${FILE_MANAGER}) ${type} done # Set default text editor TEXT_EDITOR_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${TEXT_EDITOR}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${TEXT_EDITOR}) for type in ${types[@]}; do if [[ ${type} =~ ^text.*$ ]]; then echo "Setting ${type} to ${TEXT_EDITOR_NAME}" xdg-mime default $(basename ${TEXT_EDITOR}) ${type} fi done # Set default image viewer IMAGE_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${IMAGE_VIEWER}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${IMAGE_VIEWER}) for type in ${types[@]}; do if [[ ${type} =~ ^image.*$ ]]; then echo "Setting ${type} to ${IMAGE_VIEWER_NAME}" xdg-mime default $(basename ${IMAGE_VIEWER}) ${type} fi done # Set default video viewer VIDEO_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${VIDEO_VIEWER}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${VIDEO_VIEWER}) for type in ${types[@]}; do if [[ ${type} =~ ^video.*$ ]]; then echo "Setting ${type} to ${VIDEO_VIEWER_NAME}" xdg-mime default $(basename ${VIDEO_VIEWER}) ${type} fi done # Set default PDF viewer PDF_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${PDF_VIEWER}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${PDF_VIEWER}) for type in ${types[@]}; do if [[ ${type} =~ ^application.*$ ]]; then echo "Setting ${type} to ${PDF_VIEWER_NAME}" xdg-mime default $(basename ${PDF_VIEWER}) ${type} fi done # Set communication applications MSTEAMS_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${MSTEAMS}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${MSTEAMS}) for type in ${types[@]}; do if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then echo "Setting ${type} to ${MSTEAMS_NAME}" xdg-mime default $(basename ${MSTEAMS}) ${type} fi done TS3_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${TS3}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${TS3}) for type in ${types[@]}; do if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then echo "Setting ${type} to ${TS3_NAME}" xdg-mime default $(basename ${TS3}) ${type} fi done ZOOM_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${ZOOM}) IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${ZOOM}) for type in ${types[@]}; do if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then echo "Setting ${type} to ${ZOOM_NAME}" xdg-mime default $(basename ${ZOOM}) ${type} fi done