Dev Tool: Ghost #manage /etc/hosts
Monday, March 8th, 2010
The Ruby community has really been blowing me away lately with their array of indispensable web development tools.
Ghost is no exception to this rule. It is a simple command line application for adding and removing 127.0.0.1 entries in your /etc/hosts file. I can’t believe I hadn’t thought of this sooner.
Example Usage
$ ghost add mydevsite.local
[Adding] mydevsite.local -> 127.0.0.1
$ ghost add staging-server.local 67.207.136.164
[Adding] staging-server.local -> 67.207.136.164
$ ghost list
Listing 2 host(s):
mydevsite.local -> 127.0.0.1
staging-server.local -> 67.207.136.164
$ ghost delete mydevsite.local
[Deleting] mydevsite.local
Installation
1 | sudo gem install ghost |
Yes, it’s really that easy. Make sure to checkout the GitHub Repo to contribute!
Well someone asked me for a onliner bash for that the other day…
sudo sed 1s/$/,test/ -i /etc/hosts
adds “test” to the first line of /etc/hosts… the reverse is
sudo sed 1s/,test// -i /etc/hosts
kthxbye
for more convenience you can define them as functions in your bashrc
addhost(){ sudo sed 1s/$/,$1/ -i /etc/hosts; };
delhost(){ sudo sed 1s/,$1// -i /etc/hosts; };
use as:
addhost test
delhost test
echo “127.0.0.1 omg.local” >> /etc/hosts
# emacs /etc/hosts
not surprised to see an anonymous emacs user being this dirty :P
vim ftw ;)
It's… It's a text file. How hard is it to edit a text file?
It's all about workflow. Stopping what you're doing to open up a text editor
and find/add lines of configuration can be cumbersome.