Last active
May 22, 2022 10:29
-
-
Save Eliastik/1e2b944c3eaf0205c3a85e2700ffe1a1 to your computer and use it in GitHub Desktop.
Updates the snapd desktop files of the installed Snap applications to use the system icons instead of the bundled ones. The Snap applications icons are usually stored into /snap/[Application Name]/[Number]/[Path to the icon file]. This script replace this path with [Application Name] only in the desktop file to use the system icon. This script n…
This file contains hidden or 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
#!/bin/bash | |
# Filename: update-icon-snap.sh | |
# | |
# Author: Eliastik ( eliastiksofts.com/contact ) | |
# Version 1.1 (22 may 2022) - Eliastik | |
# | |
# Changelog: | |
# | |
# Version 1.1 (22 may 2022): | |
# - Added possibility to ignore certain icons name | |
# - Added possibility to replace certain icon name with other | |
# Version 1.0 (11 june 2021): | |
# - Initial version | |
# | |
# Description: Updates the snapd desktop files of the installed Snap applications to use the system icons instead of the bundled ones. | |
# The Snap applications icons are usually stored into /snap/[Application Name]/[Number]/[Path to the icon file] | |
# This script replace this path with [Application Name] only in the desktop file to use the system icon | |
# This script need root access. | |
# Configuration variables: | |
SNAPD_PATH="/var/lib/snapd/desktop/applications" # The path to the desktop files | |
declare -A association_replace # Declare an association to replace certain icon with other | |
association_replace=( ["codium"]="code" ) # Replace certain icon name | |
ignore_icons=( "pycharm-community" "snap-store" "flutter" "zoom" ) # Ignore certain icon if your icon theme doesn't have them | |
function check_root() { | |
if [ "$(id -u)" -ne "0" ]; then | |
echo "This script must be run as root. Exiting..." 1>&2 | |
exit 1 | |
fi | |
} | |
check_root | |
if [ ! -d "${SNAPD_PATH}" ]; then | |
echo "The path doesn't exists: $SNAPD_PATH" | |
echo "Exiting..." | |
exit 1 | |
fi | |
echo "Creating temporary directory..." | |
TEMP_DIR=`mktemp -d` | |
if [[ ! "$TEMP_DIR" || ! -d "$TEMP_DIR" ]]; then | |
echo "The temporary directory could not have been created. Exiting securely..." | |
exit 1 | |
fi | |
cd "$TEMP_DIR" | |
echo "Created temporary directory at $(pwd)" | |
for filename in "$SNAPD_PATH"/*.desktop; do | |
echo "Processing: $filename" | |
fileLines=$(cat "$filename" | tr '\t' ' ' | tr '\r' ' ') | |
tmpFilename="${filename##*/}.tmp" | |
cat "$filename">>"$filename.bak" | |
echo "Backed up file to: $filename.bak" | |
while IFS= read -r line; do | |
if [[ "$line" =~ ^Icon=.* ]]; then | |
iconName=$(echo "$line" | awk -F / '{ print $3; }') | |
if [[ " ${ignore_icons[*]} " =~ " ${iconName} " ]]; then | |
echo "Ignored: ignored file $filename with icon $iconName" | |
echo "$line">>"$tmpFilename" | |
continue | |
fi | |
if [ ! -z "$iconName" ]; then | |
if [ ! -z "${association_replace[$iconName]}" ]; then | |
iconName="${association_replace[$iconName]}" | |
fi | |
echo "Icon=$iconName">>"$tmpFilename" | |
echo "Replaced: $line with Icon=$iconName" | |
else | |
echo "$line">>"$tmpFilename" | |
fi | |
else | |
echo "$line">>"$tmpFilename" | |
fi | |
done <<< "$fileLines" | |
cat "$tmpFilename">"$filename" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment