Created
July 18, 2024 15:38
-
-
Save gxanshu/8c60aad3c5b300cf49ec1c0b4ab5a301 to your computer and use it in GitHub Desktop.
Change Sublime Text icon in Linux (Ubuntu)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more at https://gxanshu.in/blogs/change-sublime-text-icon