Last active
March 29, 2023 09:54
-
-
Save echuber2/c85fadf936db3e0f54df4369e99dcd12 to your computer and use it in GitHub Desktop.
Firefox: Sink the Slack morgue to /dev/null to avoid disk usage
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 | |
# 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