Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

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