Created
October 5, 2024 12:25
-
-
Save Marcelektro/25317fc31618984ebde758588f1312f6 to your computer and use it in GitHub Desktop.
Quickly patch Vesktop desktop icon with your own on Linux systems
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
#!/bin/bash | |
DESKTOP_FILE="/var/lib/flatpak/exports/share/applications/dev.vencord.Vesktop.desktop" | |
# check if vesktop .desktop file exists | |
if [[ ! -f "$DESKTOP_FILE" ]]; then | |
echo "Error: Desktop file '$DESKTOP_FILE' not found. Are you sure you installed Vesktop via Flatpak?" | |
exit 1 | |
fi | |
# If you want to hardcode the new icon for the script to always use the same image, you can | |
# modify `NEW_ICON_PATH="$1"` line to e.g. `NEW_ICON_PATH="/home/you/Pictures/discord-logo.png"` | |
NEW_ICON_PATH="$1" | |
# the value "$1" means it will take user argument as the file | |
# check if new icon path is was provided as the first argument | |
if [[ -z "$NEW_ICON_PATH" ]]; then | |
echo "Usage: $0 <newIconPath>" | |
exit 1 | |
fi | |
# ensure provided file exists | |
if [[ ! -f "$NEW_ICON_PATH" ]]; then | |
echo "Error: File $NEW_ICON_PATH does not exist" | |
exit 1 | |
fi | |
# get the current Icon value | |
CURRENT_ICON=$(grep "^Icon=" "$DESKTOP_FILE" | cut -d'=' -f2) | |
# if line starting with Icon= doesn't exist, append it | |
if ! grep -q "^Icon=" "$DESKTOP_FILE"; then | |
echo "Error: Line starting with Icon= was not found, appending it to the file with new value..." | |
sudo echo "Icon=$NEW_ICON_PATH" >> "$DESKTOP_FILE" | |
ECHO_EXIT_CODE=$? | |
if [[ $ECHO_EXIT_CODE == 0 ]]; then | |
echo "Successfully appended Icon=$NEW_ICON_PATH line to the file." | |
else | |
echo "Error: Failed to modify file contents, echo command failed with exit code $ECHO_EXIT_CODE" | |
exit 1; | |
fi | |
else | |
# otherwise, replace the value with new one | |
sudo sed -i "s|^Icon=.*|Icon=$NEW_ICON_PATH|" "$DESKTOP_FILE" | |
SED_EXIT_CODE=$? | |
if [[ $SED_EXIT_CODE == 0 ]]; then | |
if [[ "$CURRENT_ICON" == "dev.vencord.Vesktop" ]]; then | |
echo "Successfully replaced default icon." | |
else | |
echo "Successfully replaced user-changed icon (previous value was '$CURRENT_ICON')." | |
fi | |
else | |
echo "Error: Failed to modify file contents, sed command failed with exit code $SED_EXIT_CODE" | |
exit 1; | |
fi | |
fi | |
# if the user is using GNOME, update the desktop database | |
if [[ $(echo $XDG_CURRENT_DESKTOP) == "GNOME" ]]; then | |
echo "Updating GNOME desktop database..." | |
update-desktop-database ~/.local/share/applications | |
UDD_EXIT_CODE=$? | |
if [ ! $UDD_EXIT_CODE == 0 ]; then | |
echo "Error: Failed to update desktop database, failed with exit code $UDD_EXIT_CODE. You might need to force the update manually." | |
fi | |
fi | |
echo "Operation completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment