[FarGroup/FarManager] master: Propagate current directory to the terminal (79575ac91)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Apr 2, 2026, 3:15:53 PM (14 days ago) Apr 2
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/79575ac916a788439a514bb22288b1b78494016d

>---------------------------------------------------------------

commit 79575ac916a788439a514bb22288b1b78494016d
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Thu Apr 2 20:07:14 2026 +0100

Propagate current directory to the terminal


>---------------------------------------------------------------

79575ac916a788439a514bb22288b1b78494016d
far/console.cpp | 38 ++++++++++++++++++++++++++++++++++++++
far/console.hpp | 2 ++
far/dirmix.cpp | 3 +++
far/panel.cpp | 2 ++
4 files changed, 45 insertions(+)

diff --git a/far/console.cpp b/far/console.cpp
index 432e8afce..3a0f219e9 100644
--- a/far/console.cpp
+++ b/far/console.cpp
@@ -43,6 +43,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "strmix.hpp"
#include "exception.hpp"
#include "palette.hpp"
+#include "pathmix.hpp"
#include "encoding.hpp"
#include "char_width.hpp"
#include "log.hpp"
@@ -3266,6 +3267,43 @@ protected:
send_vt_command(far::format(OSC("9001;CmdNotFound;{}"), Command));
}

+ static auto osc7(string_view const CurDir)
+ {
+ // OSC 7 is supposed to contain a proper file URI with forward slashes, percent-encoded reserved characters etc.,
+ // but it seems that implementations accept paths as is as long as they are properly prefixed.
+ // Good enough for now.
+
+ // Skip parsing if it's a boring local path, which is the vast majority of cases.
+ if (path::is_separator(CurDir.front()))
+ {
+ switch (const auto Type = ParsePath(CurDir))
+ {
+ case root_type::remote:
+ case root_type::unc_remote:
+ return far::format(OSC("7;file://"), CurDir.substr(Type == root_type::remote? L"\\\\"sv.size() : L"\\\\?\\UNC\\"sv.size()));
+
+ case root_type::win32nt_drive_letter:
+ return far::format(OSC("7;file:///"), CurDir.substr(L"\\\\?\\"sv.size()));
+
+ default:
+ // No point in converting other funny paths.
+ // They likely won't be recognized by the terminal anyway,
+ // so just send them as local and hope for the best
+ break;
+ }
+ }
+
+ return far::format(OSC("7;file:///{}"), CurDir);
+ }
+
+ void console::propagate_cd(string_view const CurDir) const
+ {
+ send_vt_command(osc7(CurDir));
+
+ // Alternative method, should work better with Windows paths
+ send_vt_command(far::format(OSC(L"9;9;{}"), CurDir));
+ }
+
std::optional<bool> console::is_grapheme_clusters_on() const
{
const auto Response = decrqm(L"2027"sv);
diff --git a/far/console.hpp b/far/console.hpp
index 222a73ddd..2106a2d2f 100644
--- a/far/console.hpp
+++ b/far/console.hpp
@@ -214,6 +214,8 @@ namespace console_detail
void command_finished(int ExitCode) const;
void command_not_found(string_view Command) const;

+ void propagate_cd(string_view CurDir) const;
+
[[nodiscard]]
std::optional<bool> is_grapheme_clusters_on() const;

diff --git a/far/dirmix.cpp b/far/dirmix.cpp
index b38ff66d3..6488b5d31 100644
--- a/far/dirmix.cpp
+++ b/far/dirmix.cpp
@@ -38,6 +38,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "dirmix.hpp"

// Internal:
+#include "console.hpp"
#include "cvtname.hpp"
#include "message.hpp"
#include "lang.hpp"
@@ -112,6 +113,7 @@ bool FarChDir(string_view const NewDir)
if (os::fs::set_current_directory(Directory))
{
set_drive_env_curdir(Directory);
+ console.propagate_cd(Directory);
return true;
}

@@ -134,6 +136,7 @@ bool FarChDir(string_view const NewDir)
if (os::fs::set_current_directory(Directory))
{
set_drive_env_curdir(Directory);
+ console.propagate_cd(Directory);
return true;
}

diff --git a/far/panel.cpp b/far/panel.cpp
index d40f36b2a..1e9814ef6 100644
--- a/far/panel.cpp
+++ b/far/panel.cpp
@@ -38,6 +38,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "panel.hpp"

// Internal:
+#include "console.hpp"
#include "keyboard.hpp"
#include "keys.hpp"
#include "filepanels.hpp"
@@ -345,6 +346,7 @@ bool Panel::SetCurPath()
if (!AnotherPanel->m_CurDir.empty() && (m_CurDir.empty() || !string_comparer_icase{}(AnotherPanel->m_CurDir[0], m_CurDir[0])))
{
set_drive_env_curdir(AnotherPanel->m_CurDir);
+ console.propagate_cd(AnotherPanel->m_CurDir);
}
}



Reply all
Reply to author
Forward
0 new messages