Skip to content

Instantly share code, notes, and snippets.

@pateketrueke
Created June 8, 2012 05:54
Show Gist options
  • Save pateketrueke/2893852 to your computer and use it in GitHub Desktop.
Save pateketrueke/2893852 to your computer and use it in GitHub Desktop.
Zsh '$ vh' clone; works on Ubuntu/Mac OSX (fixed)
vh(){
paths[0]="/etc/apache2/sites-available"
paths[1]="/etc/apache2/extra/httpd-vhosts.conf"
paths[2]="/private/etc/apache2/virtualhosts"
paths[3]="/private/etc/apache2/extra/httpd-vhosts.conf"
for i in 0 1 2 3
do
if [ -f "${paths[$i]}" ] || [ -d "${paths[$i]}" ]; then
conf="${paths[$i]}"
break
fi
done
if [ ! -f "$conf" ]; then
guess="$(ls $conf | grep $1)"
cd "$(cat $conf/$guess | grep DocumentRoot | sed s/.*DocumentRoot\ *// | sed s/\"*//g)"
return
fi
if [ -f "$conf" ]; then
cd "$(cat $conf | grep -A 10 -E ServerName\ +\"*$1 | grep DocumentRoot | sed s/.*DocumentRoot\ *// | sed s/\"*//g)"
else
echo "Not found"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment