Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No profile.d fallback in rc files #2649

Merged
merged 2 commits into from
Jul 6, 2023
Merged
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
46 changes: 23 additions & 23 deletions libmamba/src/core/shell_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,9 @@ namespace mamba
std::string
rcfile_content(const fs::u8path& env_prefix, const std::string& shell, const fs::u8path& mamba_exe)
{
std::stringstream content;

// todo use get bin dir here!
#ifdef _WIN32
std::stringstream content;
std::string cyg_mamba_exe = native_path_to_unix(mamba_exe.string());
std::string cyg_env_prefix = native_path_to_unix(env_prefix.string());
content << "\n# >>> mamba initialize >>>\n";
Expand All @@ -301,27 +300,28 @@ namespace mamba

fs::u8path env_bin = env_prefix / "bin";

content << "\n# >>> mamba initialize >>>\n";
content << "# !! Contents within this block are managed by 'mamba init' !!\n";
content << "export MAMBA_EXE=" << mamba_exe << ";\n";
content << "export MAMBA_ROOT_PREFIX=" << env_prefix << ";\n";
content << "__mamba_setup=\"$(\"$MAMBA_EXE\" shell hook --shell " << shell
<< " --root-prefix \"$MAMBA_ROOT_PREFIX\" 2> /dev/null)\"\n";
content << "if [ $? -eq 0 ]; then\n";
content << " eval \"$__mamba_setup\"\n";
content << "else\n";
content << " if [ -f " << (env_prefix / "etc" / "profile.d" / "micromamba.sh")
<< " ]; then\n";
content << " . " << (env_prefix / "etc" / "profile.d" / "micromamba.sh") << "\n";
content << " else\n";
content << " export PATH=\"" << env_bin.string().c_str() << ":$PATH\""
<< " # extra space after export prevents interference from conda init\n";
content << " fi\n";
content << "fi\n";
content << "unset __mamba_setup\n";
content << "# <<< mamba initialize <<<\n";

return content.str();
// Note that fs::path are already quoted by fmt.
return fmt::format(
"\n"
"# >>> mamba initialize >>>\n"
"# !! Contents within this block are managed by 'mamba init' !!\n"
"export MAMBA_EXE={mamba_exe_path};\n"
"export MAMBA_ROOT_PREFIX={root_prefix};\n"
R"sh(__mamba_setup="$("$MAMBA_EXE" shell hook --shell {shell} --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)")sh"
"\n"
"if [ $? -eq 0 ]; then\n"
" eval \"$__mamba_setup\"\n"
"else\n"
R"sh( alias {mamba_exe_name}="$MAMBA_EXE" # Fallback on help from mamba activate)sh"
"\n"
"fi\n"
"unset __mamba_setup\n"
"# <<< mamba initialize <<<\n",
fmt::arg("mamba_exe_path", mamba_exe),
fmt::arg("mamba_exe_name", mamba_exe.filename().string()),
fmt::arg("root_prefix", env_prefix),
fmt::arg("shell", shell)
);

#endif
}
Expand Down
10 changes: 8 additions & 2 deletions micromamba/src/activate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ set_activate_command(CLI::App* subcom)

std::string const message = fmt::format(
"\n'micromamba' is running as a subprocess and can't modify the parent shell.\n"
"Thus you must initialize your shell before using activate and deactivate.\n\n"
"Thus you must initialize your shell before using activate and deactivate.\n"
"\n"
"{0}\n"
"To automatically initialize all future ({1}) shells, run:\n"
" $ micromamba shell init --shell {1} --root-prefix=~/micromamba\n\n"
" $ micromamba shell init --shell {1} --root-prefix=~/micromamba\n"
"If your shell was already initialized, reinitialize your shell with:\n"
" $ micromamba shell reinit --shell {1}\n"
"Otherwise, this may be an issue. In the meantime you can run commands. See:\n"
" $ micromamba run --help\n"
"\n"
"Supported shells are {{bash, zsh, csh, xonsh, cmd.exe, powershell, fish}}.\n",
get_shell_hook(guessed_shell),
guessed_shell
Expand Down