Skip to content

Commit

Permalink
feat(macos): Set list of dirs ignored by Time Machine
Browse files Browse the repository at this point in the history
  • Loading branch information
mrolli committed Dec 31, 2023
1 parent c0f54cf commit 8ba7125
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions macos/macos
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
# @author Michael Rolli
# based on the very same file of Jeff Geerling. Kudos


# Warn that some commands will not be run if the script is not run as root.
if [[ $EUID -ne 0 ]]; then
RUN_AS_ROOT=false
printf "Certain commands will not be run without sudo privileges. To run as root, run the same command prepended with 'sudo', for example: $ sudo $0\n\n" | fold -s -w 80
else
RUN_AS_ROOT=true
# Update existing `sudo` timestamp until `.macos` has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
fi

# Close any open System Preferences panes, to prevent them from overriding settings we’re about to change
Expand Down Expand Up @@ -189,6 +192,7 @@ defaults write com.apple.finder FXPreferredViewStyle -string "clmv"
# Show the ~/Library folder
chflags nohidden ~/Library
exit

###############################################################################
# Dock, Dashboard, and hot corners #
###############################################################################
Expand Down Expand Up @@ -268,7 +272,7 @@ if [[ "$RUN_AS_ROOT" = true ]]; then
sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"

# Restart spotlight
killall mds > /dev/null 2>&1
killall mds >/dev/null 2>&1
fi

###############################################################################
Expand All @@ -291,14 +295,42 @@ defaults write com.apple.messageshelper.MessageController SOInputLineSettings -d
# Disable continuous spell checking
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "continuousSpellCheckingEnabled" -bool false

###############################################################################
# Time Machine #
###############################################################################

# Prevent Time Machine from prompting to use new hard drives as backup volume
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true

# Ignore certain paths from Time Machine backupss
defaults write /Library/Preferences/com.apple.TimeMachine SkipPaths

defaults write com.apple.TimeMachine SkipPaths -array \
"~mrolli/.ansible" \
"~mrolli/.ansible_async" \
"~mrolli/.cache" \
"~mrolli/.cargo" \
"~mrolli/.conda" \
"~mrolli/.docker" \
"~mrolli/.local" \
"~mrolli/.npm" \
"~mrolli/.packer.d" \
"~mrolli/.vagrant" \
"~mrolli/.vagrant.d" \
"~mrolli/Downloads/NoBackup" \
"~mrolli/VirtualBox VMs"

# Disable local Time Machine backups
#hash tmutil &> /dev/null && sudo tmutil disablelocal

###############################################################################
# Kill/restart affected applications #
###############################################################################

# Restart affected applications if `--no-restart` flag is not present.
if [[ ! ($* == *--no-restart*) ]]; then
for app in "cfprefsd" "Dock" "Finder" "Mail" "SystemUIServer" "Terminal"; do
killall "${app}" > /dev/null 2>&1
killall "${app}" >/dev/null 2>&1
done
fi

Expand Down

0 comments on commit 8ba7125

Please sign in to comment.