-
-
Save starkers/61f6816cdaf742b46a2cd4cbde0aaa33 to your computer and use it in GitHub Desktop.
v for vagrant
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
#!/usr/bin/env bash | |
# v for vagrant david@starkers.org | |
#get a list of vagrant VMs.. | |
#...I know its ugly | |
loremipsums="$(vagrant global-status | grep -A999 "^----" | grep -v "^----" | grep -B99 "The above shows information about all known Vagrant environments" | grep -v "^ $" | grep -v "The above shows information about all known Vagrant environments" | awk '{print $5,$4}')" | |
oldIFS=$IFS | |
IFS=$'\n' | |
choices=( $loremipsums ) | |
IFS=$oldIFS | |
PS3="Pick a vagrant box: " | |
set -e | |
select answer in "${choices[@]}"; do | |
for item in "${choices[@]}"; do | |
if [[ $item == $answer ]]; then | |
working_dir="$(cut -d " " -f 1 <<<"$item")" | |
echo "cd $working_dir" | |
cd "${working_dir}" | |
break 2 | |
fi | |
done | |
done | |
choices=( "up" "ssh" "suspend" "destroy -f" "resume" "provision" "halt" ) | |
PS3="choose you're weapon: " | |
select answer in "${choices[@]}"; do | |
for item in "${choices[@]}"; do | |
if [[ $item == $answer ]]; then | |
echo "Running: vagrant $item" | |
vagrant $item | |
break 2 | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment