Skip to content

Windows Terminal CWD Shell integration (OSC 9;9;) #10166

@meskill

Description

@meskill

Related problem

Windows Terminal for tracking the current dir in shell supports only osc 9;9; while nushell generates only osc 7 to track the cwd.

Describe the solution you'd like

Add output for osc 9;9; in nushell based on the docs that will allow to track the cwd in Windows Terminal.

Also, it should help with shell integration inside Vs Code that currently handles osc 7 differently that prevents from opening new instance completely on windows + nushell.

Describe alternatives you've considered

Users can add custom hook to implement this, e.g.

if $env.config.shell_integration {
  $env.config.hooks.env_change = ($env.config.hooks.env_change | upsert PWD {|config|
    let val = $config.PWD? | default []

    $val | append {|_, after|
      mut val = $after

      if not ($env.IS_WSL? | is-empty) {
        $val = (wslpath -w $val)
      }

      print -n $"(ansi -o '9;9;')($val)(ansi "st")"
    }
  })
}

I've tested this and it works good in Windows Terminal and Vs code integrated terminal. But it requires additional setup from users while Windows Terminal will soon or already become default terminal on Windows.

Additional context and details

I could make pr myself but I wanted to sure it is appropriate to add windows specific shell_integration (though, I believe many windows users will benefit from it). Also, it requires specific treatment for wsl shell i.e. converting path properly - it should be simple using embedded wslpath command but is it ok to call some external on every cwd change? (I haven't found any existing solution to convert path without utilizing call to the command)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions