cwd.go 758 B

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