ANSI escape sequence path reporting¶
ANSI escape sequence path reporting is a terminal feature that allows the shell to communicate the current working directory path back to the terminal emulator, enabling specific user interface conveniences.^[400-devops-02-os-and-linux-basics-windows.md]
Functionality¶
When this reporting is active, the shell embeds a special escape sequence into the prompt string. In Windows environments, this is commonly implemented in PowerShell profiles to output the current file system path.^[400-devops-02-os-and-linux-basics-windows.md] For example, a PowerShell function may append the sequence "$([char]27)]9;9;"\((\)loc.Path)"$([char]7)" to the prompt, where $loc.Path represents the current directory.^[400-devops-02-os-and-linux-basics-windows.md]
Use Cases¶
The primary use case for this mechanism is to facilitate Opening a tab or pane in the same directory.^[400-devops-02-os-and-linux-basics-windows.md] By receiving the path via the escape sequence, the Windows Terminal can automatically replicate the current directory when opening new tabs or panes, saving the user from manually navigating to the same location.^[400-devops-02-os-and-linux-basics-windows.md]
This feature is found in both Bash environments on Windows (via PROMPT_COMMAND) and PowerShell profiles.^[400-devops-02-os-and-linux-basics-windows.md]
Sources¶
- Opening a tab/pane in the same directory | Microsoft Learn ^[400-devops-02-os-and-linux-basics-windows.md]
- 400-devops-02-os-and-linux-basics-windows.md^[400-devops-02-os-and-linux-basics-windows.md]