From 862b3bb71083f253e6154c801e0f454b0b44798e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 19:25:49 +0000 Subject: [PATCH 1/5] Initial plan From d1ff2344994daafbb84c8443205b6e56ac1a5c51 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 19:32:15 +0000 Subject: [PATCH 2/5] Add OSC 7 support for fish and pwsh shells Co-authored-by: sawka <2722291+sawka@users.noreply.github.com> --- .../shellintegration/fish_wavefish.sh | 39 ++++++++++- .../shellintegration/pwsh_wavepwsh.sh | 67 ++++++++++++++++++- 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/pkg/util/shellutil/shellintegration/fish_wavefish.sh b/pkg/util/shellutil/shellintegration/fish_wavefish.sh index 65db91600e..c5b0b5bdeb 100644 --- a/pkg/util/shellutil/shellintegration/fish_wavefish.sh +++ b/pkg/util/shellutil/shellintegration/fish_wavefish.sh @@ -7,4 +7,41 @@ wsh token "$WAVETERM_SWAPTOKEN" fish 2>/dev/null | source set -e WAVETERM_SWAPTOKEN # Load Wave completions -wsh completion fish | source \ No newline at end of file +wsh completion fish | source + +# shell integration +function _waveterm_si_blocked + # Check if we're in tmux or screen + test -n "$TMUX" -o -n "$STY" -o "$TERM" = "tmux" -o "$TERM" = "screen" +end + +function _waveterm_si_urlencode + set -l str $argv[1] + # URL encode the path + # Escape % first + set str (string replace -a '%' '%25' -- $str) + # Common reserved characters in file paths + set str (string replace -a ' ' '%20' -- $str) + set str (string replace -a '#' '%23' -- $str) + set str (string replace -a '?' '%3F' -- $str) + set str (string replace -a '&' '%26' -- $str) + set str (string replace -a ';' '%3B' -- $str) + set str (string replace -a '+' '%2B' -- $str) + echo -n $str +end + +function _waveterm_si_osc7 + _waveterm_si_blocked; and return + set -l encoded_pwd (_waveterm_si_urlencode $PWD) + printf '\033]7;file://%s%s\007' $hostname $encoded_pwd +end + +# Hook OSC 7 to prompt and directory changes +function _waveterm_si_prompt --on-event fish_prompt + _waveterm_si_osc7 +end + +# Also update on directory change +function _waveterm_si_chpwd --on-variable PWD + _waveterm_si_osc7 +end \ No newline at end of file diff --git a/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh b/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh index 840072c362..a41060f67f 100644 --- a/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh +++ b/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh @@ -10,4 +10,69 @@ Remove-Variable -Name waveterm_swaptoken_output Remove-Item Env:WAVETERM_SWAPTOKEN # Load Wave completions -wsh completion powershell | Out-String | Invoke-Expression \ No newline at end of file +wsh completion powershell | Out-String | Invoke-Expression + +# shell integration +function Global:_waveterm_si_blocked { + # Check if we're in tmux or screen + return ($env:TMUX -or $env:STY -or $env:TERM -like "tmux*" -or $env:TERM -like "screen*") +} + +function Global:_waveterm_si_urlencode { + param([string]$str) + # URL encode the path + # Escape % first + $str = $str -replace '%', '%25' + # Common reserved characters in file paths + $str = $str -replace ' ', '%20' + $str = $str -replace '#', '%23' + $str = $str -replace '\?', '%3F' + $str = $str -replace '&', '%26' + $str = $str -replace ';', '%3B' + $str = $str -replace '\+', '%2B' + return $str +} + +function Global:_waveterm_si_osc7 { + if (_waveterm_si_blocked) { return } + + $pwd_str = $PWD.Path + + # Convert Windows path to file:// URL format + # Replace backslashes with forward slashes + $pwd_str = $pwd_str -replace '\\', '/' + + # Ensure it starts with / for proper file:// URL format + # Windows paths like C:/... need to become /C:/... + if ($pwd_str -match '^[a-zA-Z]:') { + $pwd_str = '/' + $pwd_str + } + + $encoded_pwd = _waveterm_si_urlencode $pwd_str + $hostname = $env:COMPUTERNAME + if (-not $hostname) { + $hostname = hostname + } + + # OSC 7 - current directory + Write-Host -NoNewline "`e]7;file://$hostname$encoded_pwd`a" +} + +# Hook OSC 7 to prompt +function Global:_waveterm_si_prompt { + _waveterm_si_osc7 +} + +# Add the OSC 7 call to the prompt function +if (Test-Path Function:\prompt) { + $global:_waveterm_original_prompt = $function:prompt + function Global:prompt { + _waveterm_si_prompt + & $global:_waveterm_original_prompt + } +} else { + function Global:prompt { + _waveterm_si_prompt + "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " + } +} \ No newline at end of file From 5e33cfefdbbc20cfe1c6c910ce2c63b1ef5880ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 20:18:23 +0000 Subject: [PATCH 3/5] Simplify PowerShell OSC 7 implementation per feedback Co-authored-by: sawka <2722291+sawka@users.noreply.github.com> --- .../shellintegration/pwsh_wavepwsh.sh | 39 +++++-------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh b/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh index a41060f67f..07801a9d4a 100644 --- a/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh +++ b/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh @@ -18,44 +18,23 @@ function Global:_waveterm_si_blocked { return ($env:TMUX -or $env:STY -or $env:TERM -like "tmux*" -or $env:TERM -like "screen*") } -function Global:_waveterm_si_urlencode { - param([string]$str) - # URL encode the path - # Escape % first - $str = $str -replace '%', '%25' - # Common reserved characters in file paths - $str = $str -replace ' ', '%20' - $str = $str -replace '#', '%23' - $str = $str -replace '\?', '%3F' - $str = $str -replace '&', '%26' - $str = $str -replace ';', '%3B' - $str = $str -replace '\+', '%2B' - return $str -} - function Global:_waveterm_si_osc7 { if (_waveterm_si_blocked) { return } - $pwd_str = $PWD.Path - - # Convert Windows path to file:// URL format - # Replace backslashes with forward slashes - $pwd_str = $pwd_str -replace '\\', '/' - - # Ensure it starts with / for proper file:// URL format - # Windows paths like C:/... need to become /C:/... - if ($pwd_str -match '^[a-zA-Z]:') { - $pwd_str = '/' + $pwd_str - } - - $encoded_pwd = _waveterm_si_urlencode $pwd_str + # Get hostname with fallback chain $hostname = $env:COMPUTERNAME if (-not $hostname) { - $hostname = hostname + $hostname = $env:HOSTNAME + } + if (-not $hostname) { + $hostname = [System.Net.Dns]::GetHostName() } + # Percent-encode the raw path as-is (handles UNC, drive letters, etc.) + $encoded_pwd = [System.Uri]::EscapeDataString($PWD.Path) + # OSC 7 - current directory - Write-Host -NoNewline "`e]7;file://$hostname$encoded_pwd`a" + Write-Host -NoNewline "`e]7;file://$hostname/$encoded_pwd`a" } # Hook OSC 7 to prompt From 89b3b3d7517a54c93d759964d02a65e21aea21ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 20:43:36 +0000 Subject: [PATCH 4/5] Remove DNS lookup fallback from PowerShell OSC 7 Co-authored-by: sawka <2722291+sawka@users.noreply.github.com> --- pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh b/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh index 07801a9d4a..2dfe45703d 100644 --- a/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh +++ b/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh @@ -21,14 +21,11 @@ function Global:_waveterm_si_blocked { function Global:_waveterm_si_osc7 { if (_waveterm_si_blocked) { return } - # Get hostname with fallback chain + # Get hostname (allow empty for file:/// format) $hostname = $env:COMPUTERNAME if (-not $hostname) { $hostname = $env:HOSTNAME } - if (-not $hostname) { - $hostname = [System.Net.Dns]::GetHostName() - } # Percent-encode the raw path as-is (handles UNC, drive letters, etc.) $encoded_pwd = [System.Uri]::EscapeDataString($PWD.Path) From 8323c6b0afa46465da809999f29048235d914e73 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 20:50:12 +0000 Subject: [PATCH 5/5] Use fish-native checks and built-in URL encoding Co-authored-by: sawka <2722291+sawka@users.noreply.github.com> --- .../shellintegration/fish_wavefish.sh | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/pkg/util/shellutil/shellintegration/fish_wavefish.sh b/pkg/util/shellutil/shellintegration/fish_wavefish.sh index c5b0b5bdeb..de0b623265 100644 --- a/pkg/util/shellutil/shellintegration/fish_wavefish.sh +++ b/pkg/util/shellutil/shellintegration/fish_wavefish.sh @@ -11,28 +11,14 @@ wsh completion fish | source # shell integration function _waveterm_si_blocked - # Check if we're in tmux or screen - test -n "$TMUX" -o -n "$STY" -o "$TERM" = "tmux" -o "$TERM" = "screen" -end - -function _waveterm_si_urlencode - set -l str $argv[1] - # URL encode the path - # Escape % first - set str (string replace -a '%' '%25' -- $str) - # Common reserved characters in file paths - set str (string replace -a ' ' '%20' -- $str) - set str (string replace -a '#' '%23' -- $str) - set str (string replace -a '?' '%3F' -- $str) - set str (string replace -a '&' '%26' -- $str) - set str (string replace -a ';' '%3B' -- $str) - set str (string replace -a '+' '%2B' -- $str) - echo -n $str + # Check if we're in tmux or screen (using fish-native checks) + set -q TMUX; or set -q STY; or string match -q 'tmux*' -- $TERM; or string match -q 'screen*' -- $TERM end function _waveterm_si_osc7 _waveterm_si_blocked; and return - set -l encoded_pwd (_waveterm_si_urlencode $PWD) + # Use fish-native URL encoding + set -l encoded_pwd (string escape --style=url -- $PWD) printf '\033]7;file://%s%s\007' $hostname $encoded_pwd end