Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions docs/source/user_guide/micromamba.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,100 @@ It can be used with a drop-in installation without further steps:

/path/to/micromamba create -p /tmp/env 'pytest>=8.0'
/path/to/micromamba run -p /tmp/env pytest myproject/tests

Shell Command
=============

The ``micromamba shell`` command provides functionality for launching shells and managing shell initialization scripts for environment activation.

Launching a Shell
-----------------

When used without subcommands, ``micromamba shell`` launches a new shell session in the specified environment:

.. code-block:: shell

# Launch a shell in the specified environment
micromamba shell -p /path/to/env
micromamba shell -n myenv

This is particularly useful in CI/CD environments and Docker containers where you need to work within a specific environment.

Shell Initialization Management
-------------------------------

The ``micromamba shell`` command also includes several subcommands for managing shell initialization scripts:

``micromamba shell init``
Add micromamba initialization scripts to your shell's configuration files (e.g., ``.bashrc``, ``.zshrc``).

``micromamba shell deinit``
Remove micromamba initialization scripts from your shell's configuration files.

``micromamba shell reinit``
Restore micromamba initialization scripts in your shell's configuration files.

Environment Activation Scripts
------------------------------

These subcommands generate shell-specific activation code that can be used in scripts or sourced directly:

``micromamba shell activate``
Generate activation code for the specified environment.

``micromamba shell deactivate``
Generate deactivation code to leave the current environment.

``micromamba shell reactivate``
Generate reactivation code to refresh the current environment.

``micromamba shell hook``
Generate shell hook scripts for environment activation.

.. code-block:: shell

# Generate activation code for bash
micromamba shell activate -p /path/to/env -s bash

# Generate deactivation code
micromamba shell deactivate -s bash

# Use in a script
eval "$(micromamba shell activate -p /path/to/env -s bash)"

Supported Shells
----------------

The shell command supports the following shells:

* ``bash`` - Bash shell
* ``zsh`` - Z shell
* ``fish`` - Fish shell
* ``powershell`` - PowerShell
* ``cmd.exe`` - Windows Command Prompt
* ``xonsh`` - Xonsh shell
* ``tcsh`` - Tcsh shell
* ``dash`` - Dash shell
* ``nu`` - Nu shell
* ``posix`` - POSIX-compliant shells

Common Options
--------------

``-s, --shell SHELL``
Specify the shell type. If not provided, micromamba will attempt to detect your shell automatically.

``-p, --prefix PATH``
Specify the environment by its installation path.

``-n, --name NAME``
Specify the environment by its name.

``-r, --root-prefix PATH``
Specify the root prefix (base environment location).

Platform-Specific Features
---------------------------

``micromamba shell enable_long_path_support``
On Windows, this command enables long path support, which allows working with file paths longer than 260 characters.
7 changes: 5 additions & 2 deletions micromamba/src/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ set_shell_command(CLI::App* shell_subcmd, Configuration& config)
);
set_shell_reinit_command(reinit_subsubcmd, config);

auto* hook_subsubcmd = shell_subcmd->add_subcommand("hook", "Micromamba hook scripts ");
auto* hook_subsubcmd = shell_subcmd->add_subcommand(
"hook",
"Output shell hook scripts for environment activation"
);
set_shell_hook_command(hook_subsubcmd, config);

auto* acti_subsubcmd = shell_subcmd->add_subcommand(
Expand All @@ -425,7 +428,7 @@ set_shell_command(CLI::App* shell_subcmd, Configuration& config)

auto* long_path_subsubcmd = shell_subcmd->add_subcommand(
"enable_long_path_support",
"Output deactivation code for the given shell"
"Enable long path support on Windows"
);
set_shell_long_path_command(long_path_subsubcmd, config);

Expand Down
5 changes: 4 additions & 1 deletion micromamba/src/umamba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ set_umamba_command(CLI::App* com, mamba::Configuration& config)

com->add_flag_function("--version", print_version);

CLI::App* shell_subcom = com->add_subcommand("shell", "Generate shell init scripts");
CLI::App* shell_subcom = com->add_subcommand(
"shell",
"Launch a shell or manage shell initialization scripts"
);
set_shell_command(shell_subcom, config);

CLI::App* create_subcom = com->add_subcommand("create", "Create new environment");
Expand Down
Loading