diff --git a/src/App.tsx b/src/App.tsx index dcf6828..a54b2bb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,6 +9,7 @@ import { } from './lib/terminalApi'; import { getDefaultTheme, type TerminalTheme } from './lib/terminalTheme'; import { type TerminalChunk } from './stores/useTerminalStore'; +import { extractPowerShellPromptPath } from './lib/utils'; const DEFAULT_CWD = '/workspace'; const DEFAULT_FONT_SIZE = 14; @@ -22,6 +23,7 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in const [isConnected, setIsConnected] = useState(false); const [isConnecting, setIsConnecting] = useState(false); const [error, setError] = useState(null); + const [currentPath, setCurrentPath] = useState(initialCwd); const [sessionId, setSessionId] = useState(null); const sessionIdRef = useRef(null); @@ -102,7 +104,11 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in setIsConnected(true); setIsConnecting(false); } else if (event.type === 'data' && event.data) { - const newChunk: TerminalChunk = { + const osc7Path = extractPowerShellPromptPath(event.data); + if (osc7Path) { + setCurrentPath(osc7Path); + } + const newChunk: TerminalChunk = { id: nextChunkIdRef.current++, data: event.data, }; @@ -151,7 +157,8 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in return (
{/* Panel header */} -
+
+ {currentPath} {isConnected ? '●' : isConnecting ? '○' : '○'} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f0187d3..4df0f32 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -57,3 +57,17 @@ export function isMobileDeviceViaCSS(): boolean { return false; } + +const PS_PROMPT_REGEX = /\(([^)]+)\)\s*PS\s+([^\n>]+)>|PS\s+([^\n>]+)>/g; + +export function extractPowerShellPromptPath(data: string): string | null { + let lastMatch: RegExpMatchArray | null = null; + const regex = new RegExp(PS_PROMPT_REGEX); + let match; + while ((match = regex.exec(data)) !== null) { + lastMatch = match; + } + if (!lastMatch) return null; + const path = lastMatch[3] || lastMatch[2]; + return path.trim() || null; +}