From 5b351548a40cc9ed166759a4f7c4e9a435bc1e38 Mon Sep 17 00:00:00 2001 From: Her0mAn Date: Mon, 8 Sep 2025 22:47:02 +0800 Subject: [PATCH] Fix cwd segment setting not working as expected on Windows --- src/widgets/CurrentWorkingDir.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/widgets/CurrentWorkingDir.tsx b/src/widgets/CurrentWorkingDir.tsx index 3807fa4..d7d50a0 100644 --- a/src/widgets/CurrentWorkingDir.tsx +++ b/src/widgets/CurrentWorkingDir.tsx @@ -58,14 +58,18 @@ export class CurrentWorkingDirWidget implements Widget { let displayPath = cwd; if (segments && segments > 0) { - const pathParts = cwd.split('/'); - // Remove empty strings from splitting (e.g., leading slash creates empty first element) + // Support both POSIX ('/') and Windows ('\\') separators; preserve original separator in output + const useBackslash = cwd.includes('\\') && !cwd.includes('/'); + const outSep = useBackslash ? '\\' : '/'; + + const pathParts = cwd.split(/[\\/]+/); + // Remove empty strings from splitting (e.g., leading slash or UNC leading separators) const filteredParts = pathParts.filter(part => part !== ''); if (filteredParts.length > segments) { - // Take the last N segments + // Take the last N segments and join with the detected separator const selectedSegments = filteredParts.slice(-segments); - displayPath = '.../' + selectedSegments.join('/'); + displayPath = '...' + outSep + selectedSegments.join(outSep); } }