Instance command aliases

[since version 1.8.0]

Multipass permits to create aliases to run commands on given instances. For this, there are three commands: alias, aliases and unalias.

alias creates an alias to run a command on a given instance. For instance, if one wants to run the command ls in the instance crazy-cat, it suffices to do

$ multipass alias crazy-cat:ls lscc

After running this command, the alias lscc was defined as running the command ls on the instance crazy-cat. If the alias name lscc is omitted, the alias name defaults to the name of the command to run (ls on this case).

There are two ways to execute the alias. The first one is

$ multipass lscc

This shells into the instance crazy-cat, executes ls and returns to the host command-line, as if it was an exec command.

The second way of running an alias needs the user to add the alias folder to the system path (see below), and is simply:

$ lscc

This command (given that the path was already added to the system’s path) is equivalent to multipass lscc.

To see the list of aliases defined so far, it suffices to use the aliases command. multipass aliases will give something like

Alias  Instance   Command
lscc   crazy-cat  ls

Finally, the alias can be simply removed issuing the command multipass unalias lscc. An alias is also removed when the instance for which it was defined is purged. For instance, multipass delete crazy-cat --purge will also remove the alias lscc.

Adding the alias folder to the system path

For simplicity, an alias can be executed by issuing its name, such as lscc. For this to work, a folder on which Multipass creates one script per new alias must be added to the system path. The instructions to do so are displayed the first time one creates an alias, and vary for each platform. For instance,

$ multipass alias crazy-cat:ls lscc
You'll need to add this to your shell configuration (.bashrc, .zshrc or so) for
aliases to work without prefixing with `multipass`:

PATH=/home/user/snap/multipass/common/bin:$PATH

Modifying the shell configuration file will suffice for Linux and MacOS.

For Windows, however, it is a bit more involved. To make the change permanent, we can use PowerShell to store the old system path, add our folder to it, and store the new path.

$old_path = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$new_path = “$old_path;C:\Users\user\AppData\Local\Multipass\bin”
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $new_path

And don’t forget to restart your PowerShell terminal. The folder is now permanently added to your system path, and Multipass can execute aliases just invoking their name.

See also

Documentation for alias, aliases and unalias commands.

1 Like

Very nice, thanks! I believe this merits a link from the main docs page :slight_smile:

Another way of running an alias is to use directly the alias name. For this to work, one needs to Issuing lscc

Was this leftover from edits?

This command (given that the path was already added to the system’s path) is equivalent to multipass lscc.

What path? Should this explain how to achieve that?

Hi @ricab for your comments! I updated the doc, there were certainly some leftover from the first edition and unclear things. I hope it looks better now!

1 Like