changeicon.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. echo "[Settings]"$'\n'"gtk-icon-theme-name=${ICON_THEME}" > "$HOME/.config/gtk-3.0/settings.ini"
  29. fi
  30. # GTK2
  31. if [ -f "$HOME/.gtkrc-2.0" ]; then
  32. if [ -n "$(grep 'gtk-icon-theme-name' $HOME/.gtkrc-2.0)" ]; then
  33. sed -i'' -e "s/gtk-icon-theme-name=\(.*\)/gtk-icon-theme-name=\"${ICON_THEME}\"/1" "$HOME/.gtkrc-2.0"
  34. else
  35. echo "gtk-icon-theme-name=\"${ICON_THEME}\"" >> "$HOME/.gtkrc-2.0"
  36. fi
  37. else
  38. echo "gtk-icon-theme-name=\"${ICON_THEME}\"" > "$HOME/.gtkrc-2.0"
  39. fi
  40. # Call Gsettings
  41. if [ -n "$(command -v gsettings)" ]; then
  42. gsettings set org.gnome.desktop.interface icon-theme "${ICON_THEME}"
  43. else
  44. echo 'Error: gsettings binary not found on the system. Changes might not be fully applied.'
  45. fi
  46. # Success message
  47. echo "GTK icon theme changed to $ICON_THEME. You may have to restart apps for the changes to take effect."