Created
February 24, 2026 16:34
-
-
Save zonca/20e7d7dc91301a9a04cd34b1efc59ff3 to your computer and use it in GitHub Desktop.
Bash function to update system and npm packages with version reporting
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
| up() { | |
| local npm_pkgs=("@google/gemini-cli" "@openai/codex" "opencode-ai" "@charmland/crush") | |
| declare -A old_vers | |
| echo "Checking current versions..." | |
| # Track npm versions | |
| for p in "${npm_pkgs[@]}"; do | |
| old_vers["npm:$p"]=$(npm list -g $p --depth=0 2>/dev/null | grep $p | rev | cut -d@ -f1 | rev || echo "N/A") | |
| done | |
| # Track apt upgradable versions | |
| echo "Fetching apt upgrade info..." | |
| sudo apt update > /dev/null | |
| local apt_upgradable=$(apt list --upgradable 2>/dev/null | grep '/') | |
| echo "Starting system and package updates..." | |
| sudo apt upgrade -y && npm install -g "${npm_pkgs[@]}" --force | |
| echo -e "\n--- Update Report ---" | |
| printf "%-30s | %-15s -> %-15s\n" "Package" "Old" "New" | |
| echo "------------------------------------------------------------------------" | |
| # Report apt packages that were upgraded | |
| if [ -n "$apt_upgradable" ]; then | |
| while read -r line; do | |
| local pkg_name=$(echo "$line" | cut -d/ -f1) | |
| local old_v=$(echo "$line" | awk '{print $6}' | tr -d '[]') | |
| local new_v=$(echo "$line" | awk '{print $2}') | |
| printf "%-30s | %-15s -> %-15s\n" "apt:$pkg_name" "$old_v" "$new_v" | |
| done <<< "$apt_upgradable" | |
| fi | |
| # Report npm packages | |
| for p in "${npm_pkgs[@]}"; do | |
| local new_v=$(npm list -g $p --depth=0 2>/dev/null | grep $p | rev | cut -d@ -f1 | rev || echo "N/A") | |
| printf "%-30s | %-15s -> %-15s\n" "npm:$p" "${old_vers["npm:$p"]}" "$new_v" | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment