Skip to content

Instantly share code, notes, and snippets.

@echuber2
Last active March 29, 2023 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save echuber2/c85fadf936db3e0f54df4369e99dcd12 to your computer and use it in GitHub Desktop.
Save echuber2/c85fadf936db3e0f54df4369e99dcd12 to your computer and use it in GitHub Desktop.
Firefox: Sink the Slack morgue to /dev/null to avoid disk usage
#!/bin/bash
# https://gist.github.com/echuber2/c85fadf936db3e0f54df4369e99dcd12
# Running Slack in Firefox creates a lot of temporary data in a "morgue"
# subdirectory of the local storage in your user profile. This doesn't seem to
# be necessary for it to function correctly, although it can eat up a lot of
# disk space (sometimes up to 1GB or more). Clearing the directory frequently
# helps but this process wastes disk writes on an SSD.
# To avoid any "morgue" items being created, you can try recreating a fake
# morgue item as a symlink to a non-existent directory or to /dev/null. I'm
# not really sure what the long-term side effects of doing this might be, but
# Slack still seems to work.
if [ "$(id -u)" -eq 0 ]; then
echo "Don't run this as root"
exit 1
fi
# You can find your profile directory from about:support
FF_PROFILE="$HOME/.mozilla/firefox/whatever7abcd.default"
# This part should be predictable. Make sure it matches what you already have
# on your system within the profile directory.
MORGUE_RELPATH="storage/default/https+++app.slack.com/cache/morgue"
# Doing this is in several steps to help avoid mistakes...
cd "$FF_PROFILE" || {
echo "Wrong Firefox profile directory path. Please edit the FF_PROFILE variable in the script."
exit 1
}
if [ ! -e "$MORGUE_RELPATH" ]; then
mkdir -p "$MORGUE_RELPATH"
fi
rm -rfv "$MORGUE_RELPATH" || exit
echo "Linking..."
ln -sv /dev/null "$MORGUE_RELPATH" || exit
# This can happen if you try to run this script while Firefox is still open
# and the morgue is recreated before the link step. Then you would create a
# symlink called "morgue" inside the morgue directory without a clear error
# message.
if [[ "$(realpath "$MORGUE_RELPATH")" != "/dev/null" ]]; then
echo "Error: The symlink to /dev/null was not created successfully."
exit 1
fi
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment