diff --git a/pkg/util/shellutil/shellintegration/fish_wavefish.sh b/pkg/util/shellutil/shellintegration/fish_wavefish.sh index 65db91600e..de0b623265 100644 --- a/pkg/util/shellutil/shellintegration/fish_wavefish.sh +++ b/pkg/util/shellutil/shellintegration/fish_wavefish.sh @@ -7,4 +7,27 @@ 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 (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 + # 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 + +# 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..2dfe45703d 100644 --- a/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh +++ b/pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh @@ -10,4 +10,45 @@ 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_osc7 { + if (_waveterm_si_blocked) { return } + + # Get hostname (allow empty for file:/// format) + $hostname = $env:COMPUTERNAME + if (-not $hostname) { + $hostname = $env:HOSTNAME + } + + # 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" +} + +# 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