I guess I never posted about this when I originally made it. Mark Jaquith had made a nice little “localdev” script. It provides an easy to use command line interface for adding/removing host entries for development on localhost.
I forked it into a new tool called “sandbox”. It’s the same premise but it includes a few more useful additional features:
- You can tell the tool which IP address to point to. Meaning it can be used for remote development as well as local development. (Example:
sandbox add my.domain.name 12.345.678.999)
- You can add a default address (instead of defaulting to 127.0.0.1) so you don’t need to type out the address every time you add a new rule. (Example:
sandbox destination 12.345.678.999; sandbox add my.domain.name;all future rules that don’t specify an IP in the add command will default to that)
- Methods for clearing rules, viewing all rules, or viewing specific entries.
I find it much easier than manually editing my hosts file all the time. I can also type “sandbox off” and all the rules won’t be active anymore. “sandbox on” to turn them back on. It’s super useful for when you are done working at the end of the week and no longer want to load from your development site.
The source code is at Github and is open source – and like I mentioned it’s based off of Mark’s code. It’s also the first thing I’ve ever done in Ruby. It was also a fun learning experience using Ruby, Gem, Git, and Github.
https://github.com/justinshreve/Sandbox#readme contains all of the commands.
You can also easily get going now with Ruby Gems:
gem install sandboxer
The tool has only been tested on OS X.
Let me know if you end up using this tool, if its useful to you, or if I can add anything else .