Skip to content

Instantly share code, notes, and snippets.

@ivan-leschinsky
Last active December 14, 2015 15:08
Show Gist options
  • Select an option

  • Save ivan-leschinsky/3dd96de659ad522f195e to your computer and use it in GitHub Desktop.

Select an option

Save ivan-leschinsky/3dd96de659ad522f195e to your computer and use it in GitHub Desktop.
Auto run vagrant shell for specified folders if running with Virtual box
# At the end of your .zshrc file
vagrant_folders=( '/Users/user/some_vagrant_folder' '/Users/user/some_another_vagrant_folder' )
source $HOME/vagrant_auto_run.sh
function vagrant_auto_run() {
current_dir=$PWD
full_path=$1
dir_name="$(basename $1)"
if [[ "$current_dir" == "$full_path" ]]
then
if [[ $(VBoxManage list runningvms) == *"$dir_name""_default"* ]]
then
echo "Starting 'vagrant ssh'";
eval 'vagrant ssh'
else
echo "Starting 'vagrant up' and 'vagrant ssh'";
eval 'vagrant up; vagrant ssh'
fi
fi
}
function iterate_vagrant_folders() {
emulate -L zsh
for vagrant_folder in "${vagrant_folders[@]}"
do
vagrant_auto_run $vagrant_folder
done
}
chpwd_functions=(${chpwd_functions[@]} "iterate_vagrant_folders")
iterate_vagrant_folders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment