Last active
December 14, 2015 15:08
-
-
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
This file contains hidden or 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
| # 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 |
This file contains hidden or 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_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