Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

116 righe
4.1 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/sxiv.desktop
  14. VIDEO_VIEWER=/usr/share/applications/mpv.desktop
  15. PDF_VIEWER=/usr/share/applications/org.pwmt.zathura-pdf-mupdf.desktop
  16. FILE_MANAGER=/usr/share/applications/thunar.desktop
  17. TEXT_EDITOR=/usr/share/applications/leafpad.desktop
  18. MSTEAMS=${HOME}/.local/share/applications/teams.desktop
  19. TS3=${HOME}/.local/share/applications/teamspeak.desktop
  20. ZOOM=${HOME}/.local/share/applications/zoom.desktop
  21. # Set default browser
  22. BROWSER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${BROWSER})
  23. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${BROWSER})
  24. for type in ${types[@]}; do
  25. echo "Setting ${type} to ${BROWSER_NAME}"
  26. xdg-mime default $(basename ${BROWSER}) ${type}
  27. done
  28. # Set default E-Mail client
  29. EMAIL_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${EMAIL})
  30. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${EMAIL})
  31. for type in ${types[@]}; do
  32. echo "Setting ${type} to ${EMAIL_NAME}"
  33. xdg-mime default $(basename ${EMAIL}) ${type}
  34. done
  35. # Set default file manager
  36. FILE_MANAGER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${FILE_MANAGER})
  37. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${FILE_MANAGER})
  38. for type in ${types[@]}; do
  39. echo "Setting ${type} to ${FILE_MANAGER_NAME}"
  40. xdg-mime default $(basename ${FILE_MANAGER}) ${type}
  41. done
  42. # Set default text editor
  43. TEXT_EDITOR_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${TEXT_EDITOR})
  44. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${TEXT_EDITOR})
  45. for type in ${types[@]}; do
  46. if [[ ${type} =~ ^text.*$ ]]; then
  47. echo "Setting ${type} to ${TEXT_EDITOR_NAME}"
  48. xdg-mime default $(basename ${TEXT_EDITOR}) ${type}
  49. fi
  50. done
  51. # Set default image viewer
  52. IMAGE_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${IMAGE_VIEWER})
  53. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${IMAGE_VIEWER})
  54. for type in ${types[@]}; do
  55. if [[ ${type} =~ ^image.*$ ]]; then
  56. echo "Setting ${type} to ${IMAGE_VIEWER_NAME}"
  57. xdg-mime default $(basename ${IMAGE_VIEWER}) ${type}
  58. fi
  59. done
  60. # Set default video viewer
  61. VIDEO_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${VIDEO_VIEWER})
  62. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${VIDEO_VIEWER})
  63. for type in ${types[@]}; do
  64. if [[ ${type} =~ ^video.*$ ]]; then
  65. echo "Setting ${type} to ${VIDEO_VIEWER_NAME}"
  66. xdg-mime default $(basename ${VIDEO_VIEWER}) ${type}
  67. fi
  68. done
  69. # Set default PDF viewer
  70. PDF_VIEWER_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${PDF_VIEWER})
  71. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${PDF_VIEWER})
  72. for type in ${types[@]}; do
  73. if [[ ${type} =~ ^application.*$ ]]; then
  74. echo "Setting ${type} to ${PDF_VIEWER_NAME}"
  75. xdg-mime default $(basename ${PDF_VIEWER}) ${type}
  76. fi
  77. done
  78. # Set communication applications
  79. MSTEAMS_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${MSTEAMS})
  80. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${MSTEAMS})
  81. for type in ${types[@]}; do
  82. if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then
  83. echo "Setting ${type} to ${MSTEAMS_NAME}"
  84. xdg-mime default $(basename ${MSTEAMS}) ${type}
  85. fi
  86. done
  87. TS3_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${TS3})
  88. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${TS3})
  89. for type in ${types[@]}; do
  90. if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then
  91. echo "Setting ${type} to ${TS3_NAME}"
  92. xdg-mime default $(basename ${TS3}) ${type}
  93. fi
  94. done
  95. ZOOM_NAME=$(awk -F= '/^Name=/ {print $2;exit;}' ${ZOOM})
  96. IFS=';' read -ra types <<< $(awk -F= '/MimeType/ {print $2}' ${ZOOM})
  97. for type in ${types[@]}; do
  98. if [[ ${type} =~ ^x-scheme-handler.*$ ]]; then
  99. echo "Setting ${type} to ${ZOOM_NAME}"
  100. xdg-mime default $(basename ${ZOOM}) ${type}
  101. fi
  102. done