-
-
Save millisami/9e7020ce4008d8f8be43241387c4647b to your computer and use it in GitHub Desktop.
Add lvh.me to Mac OS X hosts file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
main() { | |
if [[ $(has_lvh_me) == 1 ]]; then | |
echo 'lvh.me is already specified in your hosts file' | |
else | |
add_lvh_me | |
echo 'lvh.me was added to your hosts file!' | |
fi | |
flush_dns_cache | |
} | |
has_lvh_me() { | |
if [[ $(find_lvh_in_hosts) -eq "1" ]]; then | |
echo 1 | |
else | |
echo 0 | |
fi | |
} | |
find_lvh_in_hosts() { | |
local has_lvh=`cat /etc/hosts | grep lvh.me | wc -l` | |
if [[ "$has_lvh" -gt "0" ]]; then | |
echo "1" | |
else | |
echo "0" | |
fi | |
} | |
add_lvh_me() { | |
sudo echo '127.0.0.1 lvh.me' >> /etc/hosts | |
} | |
flush_dns_cache() { | |
if [ `sysctl -n kern.osrelease | cut -d . -f 1` -lt 9 ]; then | |
lookupd -flushcache | |
else | |
dscacheutil -flushcache | |
fi | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment