-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
26 lines (22 loc) · 1.12 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env bash
# Import ANSI escape codes for colors
source _scripts/colors.sh
if [[ -n $HOMEBREW_BUNDLE_FILE ]] && command -v brew &> /dev/null; then
printf "$GREEN%s$NORMAL\n" "🧼 Clean up Homebrew cache and dangling dependencies"
# Remove stale lock files and outdated downloads for all formulae and casks, and remove old versions of installed formulae.
brew cleanup --prune=all
# Uninstall formulae that were only installed as a dependency of another formula and are now no longer needed.
brew autoremove
# Backup Brewfile
printf "$GREEN%s$NORMAL\n" "📦 Backing up Homebrew packages"
brew bundle dump --force --file "$HOMEBREW_BUNDLE_FILE"
else
printf "$RED_BACKGROUND$BOLD%s$NORMAL\n" "❌ Failed to back up Homebrew packages. Cannot find brew."
fi
# Backup global npm packages
if command -v npm &> /dev/null; then
printf "$GREEN%s$NORMAL\n" "🚀 Backing up global npm packages"
npm ls -g --parseable | grep 'node_modules' | sed 's/.*node_modules\///' > nvm/.nvm/default-packages
else
printf "$RED%s$NORMAL\n" "❌ Failed to back up global npm packages. Cannot find npm."
fi