diff --git a/docs/source/user_guide/micromamba.rst b/docs/source/user_guide/micromamba.rst index 1c4abe1fab..6b722124ff 100644 --- a/docs/source/user_guide/micromamba.rst +++ b/docs/source/user_guide/micromamba.rst @@ -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. diff --git a/micromamba/src/shell.cpp b/micromamba/src/shell.cpp index f5fcd7fb4d..ab7af172e3 100644 --- a/micromamba/src/shell.cpp +++ b/micromamba/src/shell.cpp @@ -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( @@ -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); diff --git a/micromamba/src/umamba.cpp b/micromamba/src/umamba.cpp index d1ae4753ff..537ae0b63f 100644 --- a/micromamba/src/umamba.cpp +++ b/micromamba/src/umamba.cpp @@ -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");