Skip to content

Commit 5e33cfe

Browse files
Copilotsawka
andcommitted
Simplify PowerShell OSC 7 implementation per feedback
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent d1ff234 commit 5e33cfe

1 file changed

Lines changed: 9 additions & 30 deletions

File tree

pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,23 @@ function Global:_waveterm_si_blocked {
1818
return ($env:TMUX -or $env:STY -or $env:TERM -like "tmux*" -or $env:TERM -like "screen*")
1919
}
2020

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-
3621
function Global:_waveterm_si_osc7 {
3722
if (_waveterm_si_blocked) { return }
3823

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
24+
# Get hostname with fallback chain
5225
$hostname = $env:COMPUTERNAME
5326
if (-not $hostname) {
54-
$hostname = hostname
27+
$hostname = $env:HOSTNAME
28+
}
29+
if (-not $hostname) {
30+
$hostname = [System.Net.Dns]::GetHostName()
5531
}
5632

33+
# Percent-encode the raw path as-is (handles UNC, drive letters, etc.)
34+
$encoded_pwd = [System.Uri]::EscapeDataString($PWD.Path)
35+
5736
# OSC 7 - current directory
58-
Write-Host -NoNewline "`e]7;file://$hostname$encoded_pwd`a"
37+
Write-Host -NoNewline "`e]7;file://$hostname/$encoded_pwd`a"
5938
}
6039

6140
# Hook OSC 7 to prompt

0 commit comments

Comments
 (0)