Created
December 22, 2014 13:09
-
-
Save pesterhazy/68a0cb7a07a6dee45d3a to your computer and use it in GitHub Desktop.
in_vagrant: transparently execute command inside 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
#!/bin/bash | |
# | |
# Syntax: | |
# | |
# ./in_vagrant [command] [args] | |
# | |
# Example usage: | |
# | |
# Set up a Vagrantfile with a config called "foo" | |
# | |
# vconfig.vm.define :foo do |config| | |
# | |
# cd /your/project/directory | |
# npm install # use npm installed on the host | |
# ./in_vagrant npm install # use npm installed in the guest vm | |
# | |
# Modify VAGRANT_NAME and VAGRANT_ROOT below to fit your project structure | |
VAGRANT_NAME=foo | |
VAGRANT_ROOT=/vagrant | |
unset a | |
for arg; do | |
printf -v temp %q "$arg" | |
a+=("$temp") | |
done | |
ssh_config_cache=".vagrant-ssh.cache" | |
if [[ -f "$ssh_config_cache" ]] && test `find $ssh_config_cache -mmin +120`; then | |
rm -f "$ssh_config_cache" | |
fi | |
if [[ -f "$ssh_config_cache" ]] && ! grep -q 'User vagrant' $ssh_config_cache; then | |
rm -f "$ssh_config_cache" | |
fi | |
if [[ ! -f "$ssh_config_cache" ]]; then | |
vagrant ssh-config > "$ssh_config_cache" | |
fi | |
ssh -F "$ssh_config_cache" -t -t "$VAGRANT_NAME" cd "$VAGRANT_ROOT" '&&' "${a[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment