Skip to content

Instantly share code, notes, and snippets.

@thuandt
Last active April 1, 2020 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuandt/dd0873c4f15f85670996dc988d884ba2 to your computer and use it in GitHub Desktop.
Save thuandt/dd0873c4f15f85670996dc988d884ba2 to your computer and use it in GitHub Desktop.
Replace Sublime Text Icon in 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.
problem=$(dpkg -s imagemagick|grep installed)
echo Checking for imagemagick: "$problem"
if [ "" == "$problem" ]; then
echo "Imagemagick not installed. Installing imagemagick"
sudo apt-get --force-yes --yes install imagemagick
fi
# The directory this script is running in
THIS_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
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 "$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