diff --git a/src/env.cpp b/src/env.cpp index d5798f4b9..2819d78ed 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -1306,6 +1306,14 @@ std::shared_ptr env_stack_t::snapshot() const { return acquire_im void env_stack_t::set_argv(wcstring_list_t argv) { set(L"argv", ENV_LOCAL, std::move(argv)); } +wcstring env_stack_t::get_pwd_slash() const { + wcstring pwd = acquire_impl()->perproc_data().pwd; + if (!string_suffixes_string(L"/", pwd)) { + pwd.push_back(L'/'); + } + return pwd; +} + void env_stack_t::push(bool new_scope) { auto impl = acquire_impl(); if (new_scope) { diff --git a/src/env.h b/src/env.h index d65f66c98..873bfeaa6 100644 --- a/src/env.h +++ b/src/env.h @@ -199,7 +199,7 @@ class environment_t { virtual ~environment_t(); /// Returns the PWD with a terminating slash. - wcstring get_pwd_slash() const; + virtual wcstring get_pwd_slash() const; }; /// The null environment contains nothing. @@ -296,6 +296,9 @@ class env_stack_t final : public environment_t { /// Sets up argv as the given list of strings. void set_argv(wcstring_list_t argv); + /// Slightly optimized implementation. + wcstring get_pwd_slash() const override; + // Compatibility hack; access the "environment stack" from back when there was just one. static const std::shared_ptr &principal_ref(); static env_stack_t &principal() { return *principal_ref(); }