vagrant_local_status
is a Bash function that returns the name and status the relevant Vagrant machine for the current directory.
The primary use case is in your PS1
environment variable, so the status of your current project's Vagrant machine is always visible at every shell prompt. Here's an example of my Bash prompt in a test project dir:
[01:29 PM]-[1506]-[justin@justin]-[~/projects/test]-[dev u= bb/dev @d59dc2d]-[vagrant:poweroff]
$
(vagrant:poweroff
is the output of vagrant_local_status
)
vagrant_local_status
utilizes vagrant-global-status, a tool written in Go that replaces the slow execution of vagrant global-status
. (This super-fast exection is what makes inclusion in the shell prompt reasonable.)
- Download the
vagrant-global-status
binary and place it somewhere in your$PATH
sovagrant_local_status
can find it. (I prefer~/bin
for tools like this.) - Place the entire
vagrant_local_status
function definition into whichever startup file you use (.bash_profile
,.profile
, etc.). - Start a new shell (or
source
your startup file) and you'll then be able to runvagrant_local_status
.
Called eithout any arguments, vagrant_local_status
operates on the current directory. A single argument (the path to check) can be optionally passed (ex: vagrant_local_status ~/path/to/dir
).
If a Vagrant machine is found for the current/passed directory or its parents, a simple status is output (vm_name:vm_status
). If no Vagrant machine is defined for the directory, an empty string will be returned. If an invalid directory is passed or anything else goes wrong, an empty string will be returned.
Note: Multi-Machine Vagrant configs are not currently accounted for.
A complete example utilizing PROMPT_COMMAND
can be found in my composite_ps1
function.