Skip to content

Commit

Permalink
Homebrew tap
Browse files Browse the repository at this point in the history
  • Loading branch information
beeftornado committed Jul 17, 2014
1 parent 61e2de8 commit 79f093e
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 2 deletions.
121 changes: 119 additions & 2 deletions .gitignore
@@ -1,3 +1,95 @@
# Created by http://www.gitignore.io

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

## Directory-based project format
.idea/
# if you remove the above rule, at least ignore user-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# and these sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml

## File-based project format
*.ipr
*.iml
*.iws

## Additional for IntelliJ
out/

# generated by mpeltonen/sbt-idea plugin
.idea_modules/

# generated by JIRA plugin
atlassian-ide-plugin.xml

# generated by Crashlytics plugin (for Android Studio and Intellij)
com_crashlytics_export_strings.xml


### Eclipse ###
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# sbteclipse plugin
.target

# TeXlipse plugin
.texlipse


### Ruby ###
*.gem
*.rbc
/.config
Expand Down Expand Up @@ -27,8 +119,33 @@ build/
# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
.ruby-version
.ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc


### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp


### Linux ###
*~

# KDE directory preferences
.directory
18 changes: 18 additions & 0 deletions .project
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>homebrew-rmtree</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.projects.webnature</nature>
<nature>com.aptana.ruby.core.rubynature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions Formula/brew-rmtree.rb
@@ -0,0 +1,14 @@
require 'formula'

class BrewRmtree < Formula
homepage 'https://github.com/beeftornado/homebrew-rmtree'
url 'git://github.com/beeftornado/homebrew-rmtree.git'
version '1.0'

skip_clean 'bin'

def install
bin.install 'brew-rmtree.rb'
(bin + 'brew-rmtree.rb').chmod 0755
end
end
56 changes: 56 additions & 0 deletions README.md
Expand Up @@ -2,3 +2,59 @@ homebrew-rmtree
===============

Remove a formula and its unused dependencies

## What is it?

It's an [external command][ec] for [Homebrew][h] that provides a new command, `rmtree`,
that will uninstall that formula, examine its dependencies and uninstall them as well
if there are no remaining formula that depend on them. The command will check all dependencies
recursively starting at the one specified on the command line.

This is tricky business. The command as it stands right now is pretty straight-forward.
So this command comes with a warning.

[ec]: https://github.com/mxcl/homebrew/wiki/External-Commands
[h]: https://github.com/mxcl/homebrew

### Warning

There are formulas that do not specify all of their dependencies. This means that it is possible that
this command will remove something you still need. Until someone comes up with a clever way around this,
you need to be careful what you uninstall.

## Usage

Although the script's name is `brew-rmtree.rb`, [Homebrew external
commands][ec] work in such a way that you invoke it as `brew rmtree`. (It
functions exactly like a sub-command built into Homebrew.)

$ brew rmtree libmpc08
Uninstalling /usr/local/Cellar/libmpc08/0.8.1...
Found lingering dependencies
mpfr2
Removing dependency mpfr2...
Uninstalling /usr/local/Cellar/mpfr2/2.4.2...
Found lingering dependencies
gmp4
Removing dependency gmp4...
Uninstalling /usr/local/Cellar/gmp4/4.3.2...

## Installation

You can install `brew rmtree` in two ways.

1. Tap this repository and install via `brew` itself.

```
$ brew tap beeftornado/homebrew-rmtree && brew install brew-rmtree
```

1. Install manually.

```
$ git clone https://github.com/beeftornado/homebrew-rmtree.git && cd homebrew-rmtree
$ mv brew-rmtree.rb /usr/local/bin/ && chmod 0755 /usr/local/bin/brew-rmtree.rb
```

Once you've installed via either method, you can use the command as
described above.
84 changes: 84 additions & 0 deletions brew-rmtree.rb
@@ -0,0 +1,84 @@
require 'keg'
require 'formula'
require 'shellwords'

module BrewRmtree

USAGE = <<-EOS.undent
DESCRIPTION
`rmtree` allows you to remove a formula entirely, including all of its dependencies,
unless of course, they are used by another formula.
Warning:
Not all formulas declare their dependencies and therefore this command may end up
removing something you still need. It should be used with caution.
USAGE
brew rmtree formula1 [formula2] [formula3]...
Examples:
brew rmtree gcc44 gcc48 # Removes 'gcc44' and 'gcc48' and their dependencies
EOS

module_function

def bash(command)
escaped_command = Shellwords.escape(command)
return %x! bash -c #{escaped_command} !
end

def rmtree
if ARGV.size < 1 or ['-h', '?', '--help'].include? ARGV.first
puts USAGE
exit 0
end

raise KegUnspecifiedError if ARGV.named.empty?

if not ARGV.force?
ARGV.named.each do |keg_name|
puts bash "brew uninstall #{keg_name}"

deps = bash "join <(brew leaves) <(brew deps #{keg_name})"

if deps.length > 0
puts "Found lingering dependencies"
puts deps.chomp

deps = deps.split("\n")

deps.each do |dep|
dep = dep.chomp

if !dep.empty?
# Check if anything currently installed uses the dependency
dep_deps = bash "brew uses --installed #{dep}"
dep_deps = dep_deps.chomp

if dep_deps.length > 0
puts "Not removing dependency #{dep} because other installed packages depend on it:"
puts dep_deps
else
# Nothing claims to depend on it
puts "Removing dependency #{dep}..."
puts bash "brew rmtree #{dep}"
end
end
end
else
puts "No dependencies left on system for #{keg_name}."
end
end
else
puts "--force is not supported."
end
rescue MultipleVersionsInstalledError => e
ofail e
puts "Use `brew rmtree --force #{e.name}` to remove all versions."
end
end

BrewRmtree.rmtree
exit 0

0 comments on commit 79f093e

Please sign in to comment.