From 65c061f75c0b11e3e07327d00a62483d0223e8ca Mon Sep 17 00:00:00 2001 From: Antoine Prouvost Date: Mon, 28 Aug 2023 15:21:23 +0200 Subject: [PATCH] Use generic_string for path on Windows unix shells (#2685) --- libmamba/include/mamba/core/mamba_fs.hpp | 6 ++++++ libmamba/src/core/shell_init.cpp | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libmamba/include/mamba/core/mamba_fs.hpp b/libmamba/include/mamba/core/mamba_fs.hpp index a9d42353c8..65c515c890 100644 --- a/libmamba/include/mamba/core/mamba_fs.hpp +++ b/libmamba/include/mamba/core/mamba_fs.hpp @@ -335,6 +335,12 @@ namespace fs return this->wstring(); } + // Returns an utf-8 string using the ``/`` on all systems. + std::string generic_string() const + { + return to_utf8(m_path.generic_string()); + } + // Implicit conversion to standard path. operator std::filesystem::path() const { diff --git a/libmamba/src/core/shell_init.cpp b/libmamba/src/core/shell_init.cpp index 2c985ea671..777cbed886 100644 --- a/libmamba/src/core/shell_init.cpp +++ b/libmamba/src/core/shell_init.cpp @@ -531,19 +531,22 @@ namespace mamba if (shell == "zsh" || shell == "bash" || shell == "posix") { std::string contents = data_micromamba_sh; - util::replace_all(contents, "$MAMBA_EXE", exe.string()); + // Using /unix/like/paths on Unix shell (even on Windows) + util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); return contents; } else if (shell == "csh") { std::string contents = data_micromamba_csh; - util::replace_all(contents, "$MAMBA_EXE", exe.string()); + // Using /unix/like/paths on Unix shell (even on Windows) + util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); return contents; } else if (shell == "xonsh") { std::string contents = data_mamba_xsh; - util::replace_all(contents, "$MAMBA_EXE", exe.string()); + // Using /unix/like/paths on Unix shell (even on Windows) + util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); return contents; } else if (shell == "powershell") @@ -569,7 +572,8 @@ namespace mamba else if (shell == "fish") { std::string contents = data_mamba_fish; - util::replace_all(contents, "$MAMBA_EXE", exe.string()); + // Using /unix/like/paths on Unix shell (even on Windows) + util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); return contents; } return "";