Skip to content

Instantly share code, notes, and snippets.

@irazasyed
Created September 27, 2023 05:35
Show Gist options
  • Save irazasyed/b3cc7964864de2b0d9550d9f1f01f7bf to your computer and use it in GitHub Desktop.
Save irazasyed/b3cc7964864de2b0d9550d9f1f01f7bf to your computer and use it in GitHub Desktop.
CLI: macOS all in one update command for oh-my-zsh. Let's you run system updates for various tools and their packages including composer, npm, bun, python, ohmyzsh, brew, and more
# ~/.oh-my-zsh/custom/update.zsh
ARROW="→"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
# Run macOS Software Updates, and update Homebrew packages, brew cask updates, composer, bun, npm, and their installed packages
# Update Ruby Gems
# Disabled: Not updating system gems.
update_sys_ruby() {
#sudo gem update --system;
#sudo gem update;
sudo gem update --system -n /usr/local/bin
sudo gem update -n /usr/local/bin
}
# Update Ruby packages using RVM - Ruby Version Manager
# Disabled: Not in use.
update_rvm_ruby() {
# Upgrade RVM itself
rvm get head
rvm gemset update
rvm repair all
rvm cleanup all
}
# Update node and its packages using NVM - Node Version Manager
# Disabled: Not using anymore
update_node() {
nvm upgrade # zsh-nvm command
nvm install node --reinstall-packages-from=node
nvm install-latest-npm
npm update -g
n=$(which node); ln -s $n /usr/local/bin/node;
}
# Update yarnjs and its packages
# Disabled: https://github.com/yarnpkg/yarn/issues/1139
update_yarn() {
yarn self-update
yarn global upgrade
}
# Update Python packages using pip
update_python_packages() {
# If you want to update only selected few packages
# pip install --upgrade pip setuptools wheel
# This will attempt to update all outdated packages
pip list --outdated | awk 'NR>2 {print $1}' | while read -r package; do pip install --upgrade "$package"; done
}
# Update system packages using mas
update_system() {
sudo softwareupdate -i -a
mas upgrade
}
# Update Homebrew and Homebrew Casks
update_brew() {
# Fix permissions just in case, otherwise it won't properly function
sudo chown -R $(whoami) $(brew --prefix)/*
brew update
brew upgrade
# Cask update
# brew upgrade --cask --greedy # fallback
# Uses buo/homebrew-cask-upgrade to run cask updates
brew cu -ay
}
# Update Oh-my-zsh and plugins
update_ohmyzsh() {
omz update
# zplug (Oh-my-zsh plugins)
zplug update
}
# Update bun and global packages
update_bun() {
bun upgrade
bun update -g
}
# Update global npm packages
update_npm() {
npm update -g
}
# Update PHP PECL packages
update_php_packages() {
# Installation prefix for all extensions: /usr/local/opt/<lib name>
pear update-channels
pecl update-channels
pecl upgrade -o
}
# Update composer and its global packages
update_composer() {
composer self-update
composer outdated -D
composer global update
}
# Clean up after updates
cleanup() {
# sudo gem cleanup
# yarn cache clean
# Clean up Homebrew
brew cleanup -s --prune=all
rm -rf "$(brew --cache)"
# Clean up npm
npm cache clean --force
# Clean up Bun
bun pm cache rm -g
# Composer clear cache
composer clear-cache
# PECL clear cache
pecl clear-cache
echo -e "${GREEN}${ARROW} Success! Clean command finished.${NC}"
}
# Main update function
update() {
update_python_packages
update_system
update_brew
update_ohmyzsh
update_bun
update_npm
update_php_packages
update_composer
cleanup
# Reload Oh-my-zsh once.
source ~/.zshrc
brew doctor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment