» Aliases

Inspired in part by Git's ownalias functionality,aliases make your Vagrant experience simpler, easier, and more familiar byallowing you to create your own custom Vagrant commands.

Aliases can be defined within VAGRANT_HOME/aliases file, or in a custom filedefined using the VAGRANT_ALIAS_FILE environment variable, in the followingformat:

  1. # basic command-level aliases
  2. start = up
  3. stop = halt
  4. # advanced command-line aliases
  5. eradicate = !vagrant destroy && rm -rf .vagrant

In a nutshell, aliases are defined using a standard key = value format, wherethe key is the new Vagrant command, and the value is the aliased command.Using this format, there are two types of aliases that can be defined: internaland external aliases.

» Internal Aliases

Internal command aliases call the CLI class directly, allowing you to aliasone Vagrant command to another Vagrant command. This technique can be veryuseful for creating commands that you think should exist. For example,if vagrant stop feels more intuitive than vagrant halt, the following aliasdefinitions would make that change possible:

  1. stop = halt

This makes the following commands equivalent:

  1. vagrant stop
  2. vagrant halt

» External Aliases

While internal aliases can be used to define more intuitive Vagrant commands,external command aliases are used to define Vagrant commands with brand newfunctionality. These aliases are prefixed with the ! character, whichindicates to the interpreter that the alias should be executed as a shellcommand. For example, let's say that you want to be able to view the processorand memory utilization of the active project's virtual machine. To do this, youcould define a vagrant metrics command that returns the required informationin an easy-to-read format, like so:

  1. metrics = !ps aux | grep "[V]BoxHeadless" | grep $(cat .vagrant/machines/default/virtualbox/id) | awk '{ printf("CPU: %.02f%%, Memory: %.02f%%", $3, $4) }'

The above alias, from within the context of an active Vagrant project, wouldprint the CPU and memory utilization directly to the console:

  1. CPU: 4.20%, Memory: 11.00%