A shell script that automatically runs update commands at specified intervals when you start a new terminal session. Perfect for keeping your development tools up-to-date without manual intervention.
- ⏰ Time-based execution: Only runs updates after a specified number of days
- 🔧 Configurable commands: Define your own list of update commands
- 📝 Timestamp tracking: Remembers when updates were last run
- ⚡ Command validation: Skips commands if the program isn't installed
- 🔍 Status checking: View when updates were last executed
- 🔄 Manual reset: Force updates to run on next terminal start
-
Download the script:
curl -o ~/Scripts/auto_update_programs/auto_update_programs.sh https://raw.githubusercontent.com/your-repo/auto_update_programs.sh -
Make it executable:
chmod +x ~/Scripts/auto_update_programs/auto_update_programs.sh -
Source it in your shell config:
Add to your
~/.zshrcor~/.bashrc:source ~/Scripts/auto_update_programs/auto_update_programs.sh
Add this to your ~/.zshrc or ~/.bashrc to run updates every 7 days:
auto_update_check 7 "brew update && brew upgrade" "npm update -g" "pip install --upgrade pip"For better organization, use an array:
# Define your update commands
MY_UPDATE_COMMANDS=(
"conda update -n base -c defaults conda -y"
"brew update && brew upgrade"
"npm update -g"
"pip install --upgrade pip"
"rustup update"
"gem update --system"
)
# Run every 3 days
auto_update_check 3 "${MY_UPDATE_COMMANDS[@]}"auto_update_check [days] [commands...]- Main function to check and run updatesauto_update_status- Show when updates were last runauto_update_reset- Reset timestamp to force updates on next terminal start
# Check every 5 days with specific commands
auto_update_check 5 "brew update && brew upgrade" "npm update -g"
# Use default commands (conda, brew, npm) every 7 days
auto_update_check 7
# Check status
auto_update_status
# Force updates on next terminal start
auto_update_resetThe script stores its timestamp in ~/.auto_update_timestamp. You can safely delete this file to reset the timer.
If no commands are provided, these defaults are used:
conda update -n base -c defaults conda -ybrew update && brew upgradenpm update -g
You can customize the commands for your specific setup:
# For Python developers
PYTHON_UPDATES=(
"pip install --upgrade pip"
"conda update --all -y"
"pipx upgrade-all"
)
# For Node.js developers
NODE_UPDATES=(
"npm update -g"
"yarn global upgrade"
"pnpm update -g"
)
# For Rust developers
RUST_UPDATES=(
"rustup update"
"cargo install-update -a"
)
# Combine and run
auto_update_check 7 "${PYTHON_UPDATES[@]}" "${NODE_UPDATES[@]}" "${RUST_UPDATES[@]}"- When you start a terminal, the function checks if enough time has passed since the last update
- If yes, it runs each command in sequence
- Commands are validated before execution (skipped if the program isn't installed)
- A timestamp is saved after successful completion
- The next check won't run until the specified interval has passed
Updates not running?
- Check
auto_update_statusto see when they last ran - Use
auto_update_resetto force them to run
Command not found errors?
- The script automatically skips commands for programs that aren't installed
- Make sure your PATH is set correctly in your shell config
Want to test without waiting?
- Use
auto_update_resetthen restart your terminal - Or call
auto_update_check 0 "your commands"to bypass the time check
MIT License