changeicon.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. # Changes the GTK icon theme of the system
  3. # To run: ./changeicon.sh SomeIconThemeName
  4. # To see a list of installed icon themes: ./changeicon.sh
  5. # Icon theme not given
  6. if [ -z "${1}" ]; then
  7. echo 'Please pass an icon theme name:'
  8. echo " ${0} SomeIconThemeName"
  9. echo 'You can use these as the icon theme name:'
  10. find '/usr/share/icons/' '/usr/local/share/icons/' "$HOME/.icons/" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | while IFS= read -r line; do
  11. # To not include themes that are not actually complete icon themes
  12. if [ -d "${line}" ] && [ -f "${line}/index.theme" ]; then
  13. echo " - $(basename "$line")"
  14. fi
  15. done
  16. exit 1
  17. fi
  18. # GTK3
  19. if [ ! -d "/usr/share/icons/${1}" ] && [ ! -d "/usr/local/share/icons/${1}" ] && [ ! -d "$HOME/.icons/${1}" ]; then echo "The icon theme does not exist"; exit 2; fi
  20. ICON_THEME="${1}"
  21. if [ -f "$HOME/.config/gtk-3.0/settings.ini" ]; then
  22. if [ -n "$(grep 'gtk-icon-theme-name' $HOME/.config/gtk-3.0/settings.ini)" ]; then
  23. sed -i'' -e "s/gtk-icon-theme-name=\(.*\)/gtk-icon-theme-name=${ICON_THEME}/1" "${HOME}/.config/gtk-3.0/settings.ini"
  24. else
  25. echo "gtk-icon-theme-name=${ICON_THEME}" >> "$HOME/.config/gtk-3.0/settings.ini"
  26. fi
  27. else
  28. mkdir -p "$HOME/.config/gtk-3.0/"
  29. echo "[Settings]"$'\n'"gtk-icon-theme-name=${ICON_THEME}" > "$HOME/.config/gtk-3.0/settings.ini"
  30. fi
  31. # GTK2
  32. if [ -f "$HOME/.gtkrc-2.0" ]; then
  33. if [ -n "$(grep 'gtk-icon-theme-name' $HOME/.gtkrc-2.0)" ]; then
  34. sed -i'' -e "s/gtk-icon-theme-name=\(.*\)/gtk-icon-theme-name=\"${ICON_THEME}\"/1" "$HOME/.gtkrc-2.0"
  35. else
  36. echo "gtk-icon-theme-name=\"${ICON_THEME}\"" >> "$HOME/.gtkrc-2.0"
  37. fi
  38. else
  39. echo "gtk-icon-theme-name=\"${ICON_THEME}\"" > "$HOME/.gtkrc-2.0"
  40. fi
  41. # Call Gsettings
  42. if [ -n "$(command -v gsettings)" ]; then
  43. gsettings list-schemas | grep 'org.gnome.desktop.interface' &>/dev/null
  44. if [ "$?" -gt "0" ]; then
  45. echo 'There are no org.gnome.desktop.interface schema found. Try installing gsettings-desktop-schemas and then continue...'
  46. elif [ "$(gsettings writable org.gnome.desktop.interface icon-theme)" = 'true' ]; then
  47. gsettings set org.gnome.desktop.interface icon-theme "${ICON_THEME}"
  48. else
  49. echo 'The icon-theme key is not writable. The process may not be successful.'
  50. fi
  51. else
  52. echo 'Error: gsettings binary not found on the system. Changes might not be fully applied.'
  53. fi
  54. # Success message
  55. echo "GTK icon theme changed to $ICON_THEME. You may have to restart apps for the changes to take effect."