Debian Codegraph @

ansi/cwd.go

raw
1 package ansi
2
3 import (
4 "net/url"
5 "path"
6 )
7
8 // NotifyWorkingDirectory returns a sequence that notifies the terminal
9 // of the current working directory.
10 //
11 // OSC 7 ; Pt BEL
12 //
13 // Where Pt is a URL in the format "file://[host]/[path]".
14 // Set host to "localhost" if this is a path on the local computer.
15 //
16 // See: https://wezfurlong.org/wezterm/shell-integration.html#osc-7-escape-sequence-to-set-the-working-directory
17 // See: https://iterm2.com/documentation-escape-codes.html#:~:text=RemoteHost%20and%20CurrentDir%3A-,OSC%207,-%3B%20%5BPs%5D%20ST
18 func NotifyWorkingDirectory(host string, paths ...string) string {
19 path := path.Join(paths...)
20 u := &url.URL{
21 Scheme: "file",
22 Host: host,
23 Path: path,
24 }
25 return "\x1b]7;" + u.String() + "\x07"
26 }