Created
July 28, 2014 14:32
-
-
Save ev0rtex/3e0b9e68e0078923cb75 to your computer and use it in GitHub Desktop.
Change to directory of vagrant-managed VM
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
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