mxcl/homebrew — pull request #17151 by tinogomes (2013-01-17 22:52:13+00:00)
Title: add on_uninstall callback at formula

Let's see the rbenv formula

```ruby
require 'formula'

class Rbenv < Formula
homepage 'https://github.com/sstephenson/rbenv'
url 'https://github.com/sstephenson/rbenv/tarball/v0.4.0'
sha1 'a5e80249f985294c1c9f0914f7cbdc85d4cadd74'

head 'https://github.com/sstephenson/rbenv.git'

def install
prefix.install Dir['*']

var_lib = "#{HOMEBREW_PREFIX}/var/lib/rbenv/"
['plugins', 'versions'].each do |dir|
var_dir = "#{var_lib}/#{dir}"
mkdir_p var_dir
ln_sf var_dir, "#{prefix}/#{dir}"
end
end

def caveats; <<-EOS.undent
To enable shims and autocompletion add to your profile:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

To use Homebrew's directories rather than ~/.rbenv add to your profile:
export RBENV_ROOT=#{opt_prefix}
EOS
end
end
```

On install process, it creates directories at ```HOMEBREW_PREFIX``` (/usr/local as default) directory. So, if you uninstall rbenv ```brew uninstall rbenv```, your environment is dirty. For this case, my propose is to create an ```on_uninstall``` method into formula, like:

__WARNING: The below code may not be working.__

```ruby
require 'formula'

class Rbenv < Formula
homepage 'https://github.com/sstephenson/rbenv'
# ...

def on_uninstall
var_lib = "#{HOMEBREW_PREFIX}/var/lib/rbenv/"
puts " removing #{var_lib} directory"
['plugins', 'versions'].each do |dir|
var_dir = "#{var_lib}/#{dir}"
rm_rf "#{prefix}/#{dir}"
end
rm_rf var_lib
end
end
```