Giter VIP home page Giter VIP logo

homebrew-prune's Introduction

homebrew-prune ๐Ÿบ

A tool that identifies installed homebrew formulae, when they were last accessed, and removes them based off set date of expiry.

prune

Note

brew-autoremove removes orphaned dependencies, brew cleanup removes outdated formulae and clears old downloads/logs/cache. These are definitely un-needed, but what about 'actively updated' not orphaned packages you don't use anymore? Enter prune.

Usage

Installation:

Tap the formulae. brew tap nicknacnic/prune

Install the formulae. brew install prune

Run the formulae. prune -h

Tip

Use -t for test / dry-run purposes. prune -d 20210101 -t

Overview:

This script is designed to help clean up your macOS system by uninstalling Homebrew packages and casks that haven't been used for a significant amount of time.

How It Works:

The script operates in several steps:

  1. Date Comparison Setup: It sets up a comparison date against which the last access dates of the packages will be compared. Default is two years prior to when prune is run.

  2. Iterating Over Homebrew Packages: The script lists all packages installed via Homebrew and processes each one individually.

  3. Determining File Paths: For each package, the script checks for the presence of its main executable or library file in standard Homebrew installation paths (/usr/local/bin for executables and /usr/local/lib for libraries).

  4. Last Access Time Retrieval: If the file is found, the script retrieves its last access time using the ls -lu command.

  5. Date Parsing and Comparison: The script then parses this last access date. It handles different date formats depending on whether the date is from the current year or a previous year. The parsed date is compared against the set comparison date.

  6. Conditional Uninstallation: If a package's last access date is before the comparison date, the script uninstalls the package using brew uninstall.

  7. Logging: All actions, including checks, uninstallations, and any errors (like missing files), are logged to an output file (brew_package_usage.txt) for review.

Notes:

Important

Backup: Before running this script, ensure you have a backup of your system or at least a list of installed packages. The script will uninstall software based on the last access date, which might sometimes lead to the removal of packages still needed.

Warning

Date Formats: The script assumes specific date formats for the ls -lu output. If your system uses a different format, the script might need adjustments.

Caution

Manual Review Recommended: It's advisable to manually review the list of packages to be uninstalled before running the script, especially if you have critical Homebrew packages installed.

To Do

  • Refactor
  • Add backup function
  • Add casks to logic
  • Use built-in brew commands to locate non-default-location packages
  • brew pin catch

homebrew-prune's People

Contributors

nicknacnic avatar

Watchers

 avatar

homebrew-prune's Issues

Reinstall list bug

Add log file to /opt or /usr runtime if possible, and ensure uninstall file is properly populated

scheduler

Make default option 2 years prior to $install_date instead of 20210101. Add spring cleaning feature to run annually if possible, export a cron perhaps?

brew pin

brew pin isn't searched for, potentially old but important packages should give user prompt potentially

casks

Add feature for identifying/uninstalling casks and packages.

size parsing

The returned size of total_size_kb in process_packages and process_casks is bogus

# Calculate the size of the package using 'du' command local size_kb=$(du -sk "$install_path" | cut -f1) log_message "Size calculated for $package: $size_kb KB" total_size_kb=$((total_size_kb + size_kb))

Manually running works, shows as 0 or a very small number. Looking toward get_size function

non-standard installation path catch

Prune only works for standard installs of packages in brew --prefix, would be nice to add function to catch non-default installs using $PATH and which $command

Refactor

Adding functions into subsequent files for modular testing, build, etc.

Backup

Add a brew --list snapshot to compare before/after for reinstall, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.