Skip to content

Instantly share code, notes, and snippets.

@gxanshu
Created July 18, 2024 15:38
Show Gist options
  • Save gxanshu/8c60aad3c5b300cf49ec1c0b4ab5a301 to your computer and use it in GitHub Desktop.
Save gxanshu/8c60aad3c5b300cf49ec1c0b4ab5a301 to your computer and use it in GitHub Desktop.
Change Sublime Text icon in Linux (Ubuntu)
#!/usr/bin/env bash
##
## Replace Sublime Text icons in Ubuntu
##
if [ "$(whoami)" != "root" ]; then
echo "Script must be run as root, e.g."
echo sudo "$0"
exit 1
fi
# Check if imagemagick is installed. If not, install.
if ! dpkg -s imagemagick >/dev/null 2>&1; then
echo "Imagemagick not installed. Installing imagemagick"
sudo apt-get --force-yes --yes install imagemagick
else
echo "Imagemagick is already installed."
fi
# The directory this script is running in
THIS_DIR="$(dirname "$(realpath "$0")")"
echo "Creating Sublime Text icon set for Ubuntu"
# Convert icons and move into folders
TEMP_DIR="$THIS_DIR/TEMP"
TEMP_ICONS="$TEMP_DIR/Icon"
# shellcheck disable=SC2174
mkdir -p -m755 "$TEMP_ICONS"
# Convert icons
for SIZE in 256 128 48 32 16; do
mkdir -p "$TEMP_ICONS/${SIZE}x${SIZE}"
convert -resize "${SIZE}x${SIZE}" "${THIS_DIR}/st_icon_512.png" "${TEMP_ICONS}/${SIZE}x${SIZE}/sublime-text.png"
done
echo "Updating Sublime Text icons"
# Replace theme icons in all default locations
for dir in /usr/share/icons/*/ ~/.local/share/icons/*/; do
ICON_DIRECTORY=${dir%*/}
# Replace all icon sizes
for SIZE in 256 128 48 32 16; do
ICON_SIZE_DIRECTORY="${ICON_DIRECTORY}/${SIZE}x${SIZE}/apps/"
if [ -d "$ICON_SIZE_DIRECTORY" ]; then
cp -f "${TEMP_ICONS}/${SIZE}x${SIZE}/sublime-text.png" "${ICON_SIZE_DIRECTORY}/sublime-text.png"
fi
done
done
# Replace default Sublime Text 2 icons
SUBLIME_ICONS="/opt/sublime_text/Icon/"
# Remove existing icons
rm -rf "$SUBLIME_ICONS"
# Move new icons into place
cp -rp "$TEMP_ICONS" "$SUBLIME_ICONS"
# Remove temporary icon directory
rm -rf "$TEMP_DIR"
echo "Rebuilding icon cache"
# Rebuild icon cache for all icons
sudo find /usr/share/icons -mindepth 1 -maxdepth 1 -type d | while read -r THEME; do
if [ -f "$THEME/index.theme" ]; then
sudo gtk-update-icon-cache -f -q "$THEME"
fi
done
echo "Icon cache rebuilt successfully"
@gxanshu
Copy link
Author

gxanshu commented Jul 18, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment