Over a million developers have joined DZone.

Create Virtual Host Entries In Your NetInfo Hosts Database

·
This will generate entries for every folder in your /Sites folder so that you can address your local machine as client1.box, client2.box etc. "box' in this case is the name you give the machine in the "Sharing" prefpane. Very convenient for rapid multisite work.

ATTN: this is OS X only but you can refactor it to work on *X.


#!/usr/bin/env ruby
SitesDir = '/Sites'
DomainSuffix = `hostname`.gsub('.local', '').downcase.gsub(/\s/, '')

###############################################
`nidump hosts .`.split("\n").uniq.sort.each do | dir |
  next unless (dir.split('.').pop == DomainSuffix)
  host = dir.split("\t").pop
  cmd = `niutil -destroy . /machines/#{host}`
end

Dir.entries(SitesDir).each do | entry |
  next if (!File.stat("#{SitesDir}/#{entry}").directory? || entry == '.' || entry == '..')
  puts "> Adding website #{entry}.#{DomainSuffix}"
  `niutil -create . /machines/#{entry}.#{DomainSuffix}`
  `niutil -createprop . /machines/#{entry}.#{DomainSuffix} ip_address 127.0.0.1`
end
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}