Easily Issue "vagrant ssh -c" Commands With a "vudo" Alias


When you want to issue a command inside a running Vagrant instance instead of logging into a full blow session you can issue a single command with "vagrant ssh -c <some command>", however it's a bit of a mouthful and requires you to quote the command and you'll be in the wrong directory when the command runs.


Adding a "vudo" function to your terminal shell that aliases "vagrant ssh -c" and switches into the correct directory when it does so.

I'm using Oh My ZSH, so for me I update the ~/.zshrc with a function:

function vudo() { eval "vagrant ssh -c \"cd /vagrant && $@\"" }

Now, when I want to run something inside the vm, such as run a test suite I just type "vudo phpunit" and it fires off from the /vagrant directory. This also works for long running processes so if I want to connect to MongoDB running on Vagrant I can just type "vudo mongo" and I'm in.