"Fossies" - the Fresh Open Source Software Archive

Member "vagrant-2.2.14/website/pages/docs/cli/aliases.mdx" (20 Nov 2020, 2494 Bytes) of package /linux/misc/vagrant-2.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ---
    2 layout: docs
    3 page_title: Aliases - Command-Line Interface
    4 sidebar_title: Aliases
    5 description: |-
    6   Custom Vagrant commands can be defined using aliases, allowing for a simpler,
    7   easier, and more familiar command line interface.
    8 ---
    9 
   10 # Aliases
   11 
   12 Inspired in part by Git's own
   13 [alias functionality](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases),
   14 aliases make your Vagrant experience simpler, easier, and more familiar by
   15 allowing you to create your own custom Vagrant commands.
   16 
   17 Aliases can be defined within `VAGRANT_HOME/aliases` file, or in a custom file
   18 defined using the `VAGRANT_ALIAS_FILE` environment variable, in the following
   19 format:
   20 
   21 ```shell
   22 # basic command-level aliases
   23 start = up
   24 stop = halt
   25 
   26 # advanced command-line aliases
   27 eradicate = !vagrant destroy && rm -rf .vagrant
   28 ```
   29 
   30 In a nutshell, aliases are defined using a standard `key = value` format, where
   31 the `key` is the new Vagrant command, and the `value` is the aliased command.
   32 Using this format, there are two types of aliases that can be defined: internal
   33 and external aliases.
   34 
   35 ## Internal Aliases
   36 
   37 Internal command aliases call the CLI class directly, allowing you to alias
   38 one Vagrant command to another Vagrant command. This technique can be very
   39 useful for creating commands that you think _should_ exist. For example,
   40 if `vagrant stop` feels more intuitive than `vagrant halt`, the following alias
   41 definitions would make that change possible:
   42 
   43 ```shell
   44 stop = halt
   45 ```
   46 
   47 This makes the following commands equivalent:
   48 
   49 ```shell
   50 vagrant stop
   51 vagrant halt
   52 ```
   53 
   54 ## External Aliases
   55 
   56 While internal aliases can be used to define more intuitive Vagrant commands,
   57 external command aliases are used to define Vagrant commands with brand new
   58 functionality. These aliases are prefixed with the `!` character, which
   59 indicates to the interpreter that the alias should be executed as a shell
   60 command. For example, let's say that you want to be able to view the processor
   61 and memory utilization of the active project's virtual machine. To do this, you
   62 could define a `vagrant metrics` command that returns the required information
   63 in an easy-to-read format, like so:
   64 
   65 ```shell
   66 metrics = !ps aux | grep "[V]BoxHeadless" | grep $(cat .vagrant/machines/default/virtualbox/id) | awk '{ printf("CPU: %.02f%%, Memory: %.02f%%", $3, $4) }'
   67 ```
   68 
   69 The above alias, from within the context of an active Vagrant project, would
   70 print the CPU and memory utilization directly to the console:
   71 
   72 ```text
   73 CPU: 4.20%, Memory: 11.00%
   74 ```