Skip to content

Instantly share code, notes, and snippets.

@adam-currie
Last active August 3, 2025 14:43
Show Gist options
  • Save adam-currie/abe880f8600fa8ce0718d6c787dae696 to your computer and use it in GitHub Desktop.
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.
#!/usr/bin/env bash
# Hides all unhidden tesktop icons, or if they are all hidden already,
# unhides all (excluding dot prefixed).
#
# Bind me to a global hotkey.
#
# This method allows adding new (unhidden) files even while icons are hidden,
# at which point they can be hidden also by executing again,
# since the script only unhides when ALL icons are 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
not_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"
if (( not_all_hidden_already )); then
# HIDE ALL
# save the current desktop contents to the .hidden file to hide all file/folders
echo "$desktop_contents" > "$HIDDEN_FILE"
#else
# UNHIDE ALL
# already deleted .hidden file above so do nothing
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment