@@ -10,4 +10,69 @@ Remove-Variable -Name waveterm_swaptoken_output
1010Remove-Item Env:WAVETERM_SWAPTOKEN
1111
1212# Load Wave completions
13- wsh completion powershell | Out-String | Invoke-Expression
13+ wsh completion powershell | Out-String | Invoke-Expression
14+
15+ # shell integration
16+ function Global:_waveterm_si_blocked {
17+ # Check if we're in tmux or screen
18+ return ($env :TMUX -or $env :STY -or $env :TERM -like " tmux*" -or $env :TERM -like " screen*" )
19+ }
20+
21+ function Global:_waveterm_si_urlencode {
22+ param([string]$str )
23+ # URL encode the path
24+ # Escape % first
25+ $str = $str -replace ' %' , ' %25'
26+ # Common reserved characters in file paths
27+ $str = $str -replace ' ' , ' %20'
28+ $str = $str -replace ' #' , ' %23'
29+ $str = $str -replace ' \?' , ' %3F'
30+ $str = $str -replace ' &' , ' %26'
31+ $str = $str -replace ' ;' , ' %3B'
32+ $str = $str -replace ' \+' , ' %2B'
33+ return $str
34+ }
35+
36+ function Global:_waveterm_si_osc7 {
37+ if (_waveterm_si_blocked) { return }
38+
39+ $pwd_str = $PWD .Path
40+
41+ # Convert Windows path to file:// URL format
42+ # Replace backslashes with forward slashes
43+ $pwd_str = $pwd_str -replace ' \\' , ' /'
44+
45+ # Ensure it starts with / for proper file:// URL format
46+ # Windows paths like C:/... need to become /C:/...
47+ if ($pwd_str -match ' ^[a-zA-Z]:' ) {
48+ $pwd_str = ' /' + $pwd_str
49+ }
50+
51+ $encoded_pwd = _waveterm_si_urlencode $pwd_str
52+ $hostname = $env :COMPUTERNAME
53+ if (-not $hostname ) {
54+ $hostname = hostname
55+ }
56+
57+ # OSC 7 - current directory
58+ Write-Host -NoNewline " ` e]7; file://$hostname$encoded_pwd ` a"
59+ }
60+
61+ # Hook OSC 7 to prompt
62+ function Global:_waveterm_si_prompt {
63+ _waveterm_si_osc7
64+ }
65+
66+ # Add the OSC 7 call to the prompt function
67+ if (Test-Path Function:\p rompt) {
68+ $global :_waveterm_original_prompt = $function :prompt
69+ function Global:prompt {
70+ _waveterm_si_prompt
71+ & $global :_waveterm_original_prompt
72+ }
73+ } else {
74+ function Global:prompt {
75+ _waveterm_si_prompt
76+ " PS $( $executionContext .SessionState.Path.CurrentLocation) $( ' >' * ($nestedPromptLevel + 1)) "
77+ }
78+ }
0 commit comments