diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/vagrant/cli%2Faliases.html | |
new repository
Diffstat (limited to 'devdocs/vagrant/cli%2Faliases.html')
| -rw-r--r-- | devdocs/vagrant/cli%2Faliases.html | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/devdocs/vagrant/cli%2Faliases.html b/devdocs/vagrant/cli%2Faliases.html new file mode 100644 index 00000000..ce38a939 --- /dev/null +++ b/devdocs/vagrant/cli%2Faliases.html @@ -0,0 +1,21 @@ +<h1 id="aliases"> Aliases </h1> <p>Inspired in part by Git's own <a href="https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases">alias functionality</a>, aliases make your Vagrant experience simpler, easier, and more familiar by allowing you to create your own custom Vagrant commands.</p> <p>Aliases can be defined within <code>VAGRANT_HOME/aliases</code> file, or in a custom file defined using the <code>VAGRANT_ALIAS_FILE</code> environment variable, in the following format:</p> <div class="highlight"><pre class="highlight plaintext"># basic command-level aliases +start = up +stop = halt + +# advanced command-line aliases +eradicate = !vagrant destroy && rm -rf .vagrant +</pre></div> +<p>In a nutshell, aliases are defined using a standard <code>key = value</code> format, where the <code>key</code> is the new Vagrant command, and the <code>value</code> is the aliased command. Using this format, there are two types of aliases that can be defined: internal and external aliases.</p> <h2 id="internal-aliases"> Internal Aliases </h2> <p>Internal command aliases call the CLI class directly, allowing you to alias one Vagrant command to another Vagrant command. This technique can be very useful for creating commands that you think <em>should</em> exist. For example, if <code>vagrant stop</code> feels more intuitive than <code>vagrant halt</code>, the following alias definitions would make that change possible:</p> <div class="highlight"><pre class="highlight plaintext">stop = halt +</pre></div> +<p>This makes the following commands equivalent:</p> <div class="highlight"><pre class="highlight plaintext">vagrant stop +vagrant halt +</pre></div> +<h2 id="external-aliases"> External Aliases </h2> <p>While internal aliases can be used to define more intuitive Vagrant commands, external command aliases are used to define Vagrant commands with brand new functionality. These aliases are prefixed with the <code>!</code> character, which indicates to the interpreter that the alias should be executed as a shell command. For example, let's say that you want to be able to view the processor and memory utilization of the active project's virtual machine. To do this, you could define a <code>vagrant metrics</code> command that returns the required information in an easy-to-read format, like so:</p> <div class="highlight"><pre class="highlight plaintext">metrics = !ps aux | grep "[V]BoxHeadless" | grep $(cat .vagrant/machines/default/virtualbox/id) | awk '{ printf("CPU: %.02f%%, Memory: %.02f%%", $3, $4) }' +</pre></div> +<p>The above alias, from within the context of an active Vagrant project, would print the CPU and memory utilization directly to the console:</p> <div class="highlight"><pre class="highlight plaintext">CPU: 4.20%, Memory: 11.00% +</pre></div><div class="_attribution"> + <p class="_attribution-p"> + © 2010–2018 Mitchell Hashimoto<br>Licensed under the MPL 2.0 License.<br> + <a href="https://www.vagrantup.com/docs/cli/aliases.html" class="_attribution-link">https://www.vagrantup.com/docs/cli/aliases.html</a> + </p> +</div> |
