Skip to content

Code-Samples-Galore/Terminal-Auto-Update-Programs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🔄 Auto Update Programs

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.

✨ Features

  • 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

⚙️ Installation

  1. Download the script:

    curl -o ~/Scripts/auto_update_programs/auto_update_programs.sh https://raw.githubusercontent.com/your-repo/auto_update_programs.sh
  2. Make it executable:

    chmod +x ~/Scripts/auto_update_programs/auto_update_programs.sh
  3. Source it in your shell config:

    Add to your ~/.zshrc or ~/.bashrc:

    source ~/Scripts/auto_update_programs/auto_update_programs.sh

🚀 Usage

🔰 Basic Usage

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"

🧑‍💻 Advanced Usage with Array

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[@]}"

🛠️ Available Functions

  • auto_update_check [days] [commands...] - Main function to check and run updates
  • auto_update_status - Show when updates were last run
  • auto_update_reset - Reset timestamp to force updates on next terminal start

💡 Examples

# 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_reset

📝 Configuration

The script stores its timestamp in ~/.auto_update_timestamp. You can safely delete this file to reset the timer.

🏗️ Default Commands

If no commands are provided, these defaults are used:

  • conda update -n base -c defaults conda -y
  • brew update && brew upgrade
  • npm update -g

🎨 Customization

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[@]}"

🧩 How It Works

  1. When you start a terminal, the function checks if enough time has passed since the last update
  2. If yes, it runs each command in sequence
  3. Commands are validated before execution (skipped if the program isn't installed)
  4. A timestamp is saved after successful completion
  5. The next check won't run until the specified interval has passed

🛠️ Troubleshooting

Updates not running?

  • Check auto_update_status to see when they last ran
  • Use auto_update_reset to 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_reset then restart your terminal
  • Or call auto_update_check 0 "your commands" to bypass the time check

📄 License

MIT License

About

Auto update terminal programs.

Topics

Resources

License

Stars

Watchers

Forks

Languages