Created
November 29, 2025 09:20
-
-
Save AndrewDongminYoo/3bf383edc02e5e7efb14e054394e4187 to your computer and use it in GitHub Desktop.
Setting up a cron job or adding an alias to your shell profile for a shell script that mimics the exact experience of running `brew upgrade` in Homebrew to upgrade all Dart global packages is super convenient!
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # ANSI codes | |
| BOLD="\033[1m" | |
| GREEN="\033[32m" | |
| YELLOW="\033[33m" | |
| RED="\033[31m" | |
| BLUE="\033[34m" | |
| GRAY="\033[90m" | |
| RESET="\033[0m" | |
| echo -e "${BOLD}==> Updating Dart pub global packages...${RESET}" | |
| dart pub global list | awk '{print $1}' | while read -r pkg; do | |
| [ -z "$pkg" ] && continue | |
| echo -e "${BLUE}==>${RESET} Checking ${BOLD}$pkg${RESET}" | |
| output="$(dart pub global activate "$pkg" 2>&1)" | |
| exit_code=$? | |
| if [ $exit_code -ne 0 ]; then | |
| echo -e " ${RED}✗ Failed:${RESET} $pkg" | |
| printf '%s\n' "$output" | |
| continue | |
| fi | |
| if echo "$output" | grep -q "already activated at newest available version"; then | |
| echo -e " ${GRAY}${pkg} is already up-to-date.${RESET}" | |
| else | |
| printf '%s\n' "$output" | |
| echo -e " ${GREEN}✓ Updated:${RESET} $pkg" | |
| fi | |
| echo | |
| done | |
| echo -e "${GREEN}✓${RESET} All Dart global packages are up-to-date." |
Author
AndrewDongminYoo
commented
Nov 29, 2025
I love it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment