Skip to content

Instantly share code, notes, and snippets.

@nickludlam
Last active December 11, 2015 21:58
Show Gist options
  • Save nickludlam/4666172 to your computer and use it in GitHub Desktop.
Save nickludlam/4666172 to your computer and use it in GitHub Desktop.
A section of my .profile which puts the running VM count into the prompt.
function parse_vagrant_vms {
# Use sed to strip out the whitespace, can't seem to get wc to give nice formatting standalone
# Thanks to @pkqk for showing me the speedy 'VBoxManage' command
local vm_count=$(VBoxManage list runningvms | wc -l | sed 's/^ *//; s/; */;/g')
# I use curly braces to mean vm count, edit to taste
if [ $vm_count -eq 1 ]; then
echo "{${vm_count}vm}"
fi
if [ $vm_count -gt 1 ]; then
echo "{${vm_count}vms}"
fi
}
# In my true profile, there's a lot more in PS1 than this, but I've edited for brevity
export PS1="\$(parse_vagrant_vms)\n\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment