You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

96 lines
3.4 KiB

  1. #!/usr/bin/env bash
  2. #==============================================================================
  3. #title : sanemime.sh
  4. #description : Resets MIMe configuration to sane defaults in case any shitty
  5. # software broke it.
  6. #author : hmk
  7. #date : 20210620
  8. #version : 0.4
  9. #==============================================================================
  10. cp ${HOME}/.config/mimeapps.list ${HOME}/.config/mimeapps.list.bak
  11. BROWSER=/usr/share/applications/firefox.desktop
  12. EMAIL=${HOME}/.local/share/applications/neomutt.desktop
  13. #IMAGE_VIEWER=/usr/share/applications/feh.desktop
  14. IMAGE_VIEWER=/usr/share/applications/sxiv.desktop
  15. VIDEO_VIEWER=/usr/share/applications/mpv.desktop
  16. PDF_VIEWER=/usr/share/applications/org.pwmt.zathura-pdf-mupdf.desktop
  17. MSTEAMS=${HOME}/.local/share/applications/teams.desktop
  18. TS3=${HOME}/.local/share/applications/teamspeak.desktop
  19. ZOOM=${HOME}/.local/share/applications/zoom.desktop
  20. # Set default browser
  21. BROWSER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${BROWSER})
  22. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${BROWSER})
  23. for type in ${types[@]}; do
  24. echo "Setting ${type} to ${BROWSER_NAME}"
  25. xdg-mime default $(basename ${BROWSER}) ${type}
  26. done
  27. # Set default E-Mail client
  28. EMAIL_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${EMAIL})
  29. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${EMAIL})
  30. for type in ${types[@]}; do
  31. echo "Setting ${type} to ${EMAIL_NAME}"
  32. xdg-mime default $(basename ${EMAIL}) ${type}
  33. done
  34. # Set default image viewer
  35. IMAGE_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${IMAGE_VIEWER})
  36. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${IMAGE_VIEWER})
  37. for type in ${types[@]}; do
  38. if [[ ${type} =~ ^image.*$ ]]; then
  39. echo "Setting ${type} to ${IMAGE_VIEWER_NAME}"
  40. xdg-mime default $(basename ${IMAGE_VIEWER}) ${type}
  41. fi
  42. done
  43. # Set default video viewer
  44. VIDEO_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${VIDEO_VIEWER})
  45. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${VIDEO_VIEWER})
  46. for type in ${types[@]}; do
  47. if [[ ${type} =~ ^video.*$ ]]; then
  48. echo "Setting ${type} to ${VIDEO_VIEWER_NAME}"
  49. xdg-mime default $(basename ${VIDEO_VIEWER}) ${type}
  50. fi
  51. done
  52. # Set default PDF viewer
  53. PDF_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${PDF_VIEWER})
  54. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${PDF_VIEWER})
  55. for type in ${types[@]}; do
  56. if [[ ${type} =~ ^application.*$ ]]; then
  57. echo "Setting ${type} to ${PDF_VIEWER_NAME}"
  58. xdg-mime default $(basename ${PDF_VIEWER}) ${type}
  59. fi
  60. done
  61. # Set communication applications
  62. MSTEAMS_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${MSTEAMS})
  63. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${MSTEAMS})
  64. for type in ${types[@]}; do
  65. if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then
  66. echo "Setting ${type} to ${MSTEAMS_NAME}"
  67. xdg-mime default $(basename ${MSTEAMS}) ${type}
  68. fi
  69. done
  70. TS3_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${TS3})
  71. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${TS3})
  72. for type in ${types[@]}; do
  73. if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then
  74. echo "Setting ${type} to ${TS3_NAME}"
  75. xdg-mime default $(basename ${TS3}) ${type}
  76. fi
  77. done
  78. ZOOM_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${ZOOM})
  79. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${ZOOM})
  80. for type in ${types[@]}; do
  81. if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then
  82. echo "Setting ${type} to ${ZOOM_NAME}"
  83. xdg-mime default $(basename ${ZOOM}) ${type}
  84. fi
  85. done