Last active
August 26, 2024 22:33
-
-
Save adam-currie/abe880f8600fa8ce0718d6c787dae696 to your computer and use it in GitHub Desktop.
Hides all desktop icons, or shows them if they're all hidden already.
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
#!/usr/bin/env bash | |
# Hides all unhidden tesktop icons, or if they are all hidden already, | |
# unhides all (excluding dot prefixed). | |
# (this way allows adding to desktop even if all is hidden) | |
# NOTE: your DE/file manager has to support .hidden files (different from just supporting hiding files prepended with '.') | |
# afaik its supported with the major distros/file managers (gnome, plasma, xfce) | |
DESKTOP_DIR=~/Desktop | |
HIDDEN_FILE="$DESKTOP_DIR/.hidden" | |
HELP_MSG="Hides all desktop icons, or shows them if they're all hidden already." | |
# Check for --help or -h argument | |
if [[ "$1" == "--help" || "$1" == "-h" ]]; then | |
echo "$HELP_MSG" | |
exit 0 | |
fi | |
# Get whats on the desktop | |
desktop_contents=$(ls -1 "$DESKTOP_DIR") | |
# Check if the file exists and its contents match the current desktop_contents | |
[ -f "$HIDDEN_FILE" ] && echo "$desktop_contents" | diff -q - "$HIDDEN_FILE" > /dev/null | |
all_hidden_already=$? | |
# Remove the .hidden file if it exists | |
# this is needed regardless of state because we need to change | |
# the state of existence of the file in order to trigger it to update the ui | |
rm "$HIDDEN_FILE" | |
# Show/Hide all desktop files/folders | |
if [ "$all_hidden_already" -eq 0 ]; then | |
# already deleted .hidden file above so do nothing | |
echo "Unhiding all desktop icons." | |
else | |
# save the current desktop contents to the .hidden file to hide all file/folders | |
echo "$desktop_contents" > "$HIDDEN_FILE" | |
echo "Hiding all desktop icons." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment