Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ev0rtex
Created July 28, 2014 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ev0rtex/3e0b9e68e0078923cb75 to your computer and use it in GitHub Desktop.
Save ev0rtex/3e0b9e68e0078923cb75 to your computer and use it in GitHub Desktop.
Change to directory of vagrant-managed VM
function vagrant-cd() {
VMS=()
OLD=$IFS
IFS=$'\r\n'
for line in $(vagrant global-status | egrep "^[a-z0-9]{7}\s" -); do
VMS+=($line)
done
IFS=$OLD
if [[ -z "$1" ]]; then
printf "%s\n" "${VMS[@]}"
else
for i in $(seq 1 ${#VMS[@]}); do
vm=(${(s: :)VMS[$i]})
if [[ ${#vm} > 0 ]]; then
if [[ "$1" == "${vm[1]}" || "$1" == "${vm[2]}" ]]; then
cd "${vm[5]}"
return
fi
fi
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment