2025-10-17 19:19:40 +00:00
|
|
|
# this file is sourced with -C
|
|
|
|
|
# Add Wave binary directory to PATH
|
|
|
|
|
set -x PATH {{.WSHBINDIR}} $PATH
|
|
|
|
|
|
|
|
|
|
# Source dynamic script from wsh token (the echo is to prevent fish from complaining about empty input)
|
|
|
|
|
wsh token "$WAVETERM_SWAPTOKEN" fish 2>/dev/null | source
|
|
|
|
|
set -e WAVETERM_SWAPTOKEN
|
|
|
|
|
|
|
|
|
|
# Load Wave completions
|
Add OSC 7 support for Fish and PowerShell shells (#2456)
## Overview
This PR implements OSC 7 (current working directory reporting) support
for Fish shell and PowerShell, completing the shell integration coverage
alongside the existing Bash and Zsh implementations added in #2444.
## What is OSC 7?
OSC 7 is an operating system command that allows shells to automatically
report their current working directory to the terminal emulator using
the format:
```
ESC]7;file://hostname/path BEL
```
This enables the terminal to track the current directory without manual
commands, providing better context for AI features and ensuring accurate
path information.
## Implementation Details
### Fish Shell (`fish_wavefish.sh`)
Added shell integration functions using Fish-native features:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
using `set -q` and `string match -q`
- `_waveterm_si_osc7()` - Sends the OSC 7 sequence with built-in URL
encoding
- Uses `string escape --style=url` for UTF-8 percent-encoding
- Hooked to `fish_prompt` event and `PWD` variable changes for automatic
updates
**Key Features:**
- Fish-native checks (`set -q`, `string match`) instead of non-portable
`test -o`
- Built-in `string escape --style=url` for proper UTF-8 percent-encoding
- Simple, portable, and maintainable (32 lines total)
### PowerShell (`pwsh_wavepwsh.sh`)
Added simplified shell integration that leverages frontend
normalization:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
- `_waveterm_si_osc7()` - Sends OSC 7 with raw path encoding
- Uses `[System.Uri]::EscapeDataString()` for proper percent-encoding
- Integrated into the prompt function while preserving existing prompts
**Key Features:**
- **No path rewriting**: Sends raw paths (e.g., `C:\Users\Name` →
`C%3A%5CUsers%5CName`)
- **UNC support**: Network paths like `\\server\share` encoded as
`%5C%5Cserver%5Cshare`
- **Hostname fallback**: `$env:COMPUTERNAME` → `$env:HOSTNAME` → empty
(produces `file:///path`)
- **No DNS lookup**: Avoids potentially slow DNS calls
- Simple and efficient (53 lines total)
## Implementation Benefits
Both implementations use native, built-in features for maximum
compatibility and maintainability:
**Fish:**
- ✅ Replaced `test -o` with fish-native `set -q` and `string match -q`
for better portability
- ✅ Replaced manual string replacements with `string escape --style=url`
for proper UTF-8 support
- ✅ Removed custom URL encoding function (19 lines removed)
**PowerShell:**
- ✅ Uses built-in `[System.Uri]::EscapeDataString()` for proper
percent-encoding
- ✅ No path rewriting - frontend handles normalization via
`decodeURIComponent()` and backslash conversion
- ✅ Proper UNC path support without special-casing
- ✅ Removed DNS lookup to avoid slow operations
- ✅ Removed custom URL encoding function
## Testing
All implementations were tested for:
- ✅ URL encoding of special characters (spaces, #, ?, &, ;, +, %)
- ✅ Correct OSC 7 format generation
- ✅ Fish-native checks work correctly (TMUX, STY, TERM patterns)
- ✅ Raw path encoding (PowerShell - no rewriting)
- ✅ UNC path support (PowerShell)
- ✅ Unix path handling
- ✅ Go package compilation
- ✅ No security issues (CodeQL)
## Path Handling Examples
**Fish:**
- `/home/user` → `/home/user`
- `/path with spaces` → `/path%20with%20spaces`
- `/file#hash` → `/file%23hash`
**PowerShell:**
- Windows: `C:\Users\Name` → `file://HOST/C%3A%5CUsers%5CName`
- UNC: `\\server\share\folder` →
`file://HOST/%5C%5Cserver%5Cshare%5Cfolder`
- Empty hostname: produces `file:///path` format
## Files Changed
- `pkg/util/shellutil/shellintegration/fish_wavefish.sh` (+22 lines, -18
lines = net +4 lines, but 19 lines of custom code removed)
- `pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh` (+26 lines, -51
lines = net -25 lines)
Total: 38 fewer lines of code with better functionality and
maintainability.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2025-10-18 00:23:08 +00:00
|
|
|
wsh completion fish | source
|
|
|
|
|
|
2025-10-21 00:29:38 +00:00
|
|
|
set -g _WAVETERM_SI_FIRSTPROMPT 1
|
|
|
|
|
|
Add OSC 7 support for Fish and PowerShell shells (#2456)
## Overview
This PR implements OSC 7 (current working directory reporting) support
for Fish shell and PowerShell, completing the shell integration coverage
alongside the existing Bash and Zsh implementations added in #2444.
## What is OSC 7?
OSC 7 is an operating system command that allows shells to automatically
report their current working directory to the terminal emulator using
the format:
```
ESC]7;file://hostname/path BEL
```
This enables the terminal to track the current directory without manual
commands, providing better context for AI features and ensuring accurate
path information.
## Implementation Details
### Fish Shell (`fish_wavefish.sh`)
Added shell integration functions using Fish-native features:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
using `set -q` and `string match -q`
- `_waveterm_si_osc7()` - Sends the OSC 7 sequence with built-in URL
encoding
- Uses `string escape --style=url` for UTF-8 percent-encoding
- Hooked to `fish_prompt` event and `PWD` variable changes for automatic
updates
**Key Features:**
- Fish-native checks (`set -q`, `string match`) instead of non-portable
`test -o`
- Built-in `string escape --style=url` for proper UTF-8 percent-encoding
- Simple, portable, and maintainable (32 lines total)
### PowerShell (`pwsh_wavepwsh.sh`)
Added simplified shell integration that leverages frontend
normalization:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
- `_waveterm_si_osc7()` - Sends OSC 7 with raw path encoding
- Uses `[System.Uri]::EscapeDataString()` for proper percent-encoding
- Integrated into the prompt function while preserving existing prompts
**Key Features:**
- **No path rewriting**: Sends raw paths (e.g., `C:\Users\Name` →
`C%3A%5CUsers%5CName`)
- **UNC support**: Network paths like `\\server\share` encoded as
`%5C%5Cserver%5Cshare`
- **Hostname fallback**: `$env:COMPUTERNAME` → `$env:HOSTNAME` → empty
(produces `file:///path`)
- **No DNS lookup**: Avoids potentially slow DNS calls
- Simple and efficient (53 lines total)
## Implementation Benefits
Both implementations use native, built-in features for maximum
compatibility and maintainability:
**Fish:**
- ✅ Replaced `test -o` with fish-native `set -q` and `string match -q`
for better portability
- ✅ Replaced manual string replacements with `string escape --style=url`
for proper UTF-8 support
- ✅ Removed custom URL encoding function (19 lines removed)
**PowerShell:**
- ✅ Uses built-in `[System.Uri]::EscapeDataString()` for proper
percent-encoding
- ✅ No path rewriting - frontend handles normalization via
`decodeURIComponent()` and backslash conversion
- ✅ Proper UNC path support without special-casing
- ✅ Removed DNS lookup to avoid slow operations
- ✅ Removed custom URL encoding function
## Testing
All implementations were tested for:
- ✅ URL encoding of special characters (spaces, #, ?, &, ;, +, %)
- ✅ Correct OSC 7 format generation
- ✅ Fish-native checks work correctly (TMUX, STY, TERM patterns)
- ✅ Raw path encoding (PowerShell - no rewriting)
- ✅ UNC path support (PowerShell)
- ✅ Unix path handling
- ✅ Go package compilation
- ✅ No security issues (CodeQL)
## Path Handling Examples
**Fish:**
- `/home/user` → `/home/user`
- `/path with spaces` → `/path%20with%20spaces`
- `/file#hash` → `/file%23hash`
**PowerShell:**
- Windows: `C:\Users\Name` → `file://HOST/C%3A%5CUsers%5CName`
- UNC: `\\server\share\folder` →
`file://HOST/%5C%5Cserver%5Cshare%5Cfolder`
- Empty hostname: produces `file:///path` format
## Files Changed
- `pkg/util/shellutil/shellintegration/fish_wavefish.sh` (+22 lines, -18
lines = net +4 lines, but 19 lines of custom code removed)
- `pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh` (+26 lines, -51
lines = net -25 lines)
Total: 38 fewer lines of code with better functionality and
maintainability.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2025-10-18 00:23:08 +00:00
|
|
|
# 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
|
2025-10-21 00:29:38 +00:00
|
|
|
set -l encoded_pwd (string escape --style=url -- "$PWD")
|
2025-11-20 20:42:17 +00:00
|
|
|
printf '\033]7;file://localhost%s\007' $encoded_pwd
|
Add OSC 7 support for Fish and PowerShell shells (#2456)
## Overview
This PR implements OSC 7 (current working directory reporting) support
for Fish shell and PowerShell, completing the shell integration coverage
alongside the existing Bash and Zsh implementations added in #2444.
## What is OSC 7?
OSC 7 is an operating system command that allows shells to automatically
report their current working directory to the terminal emulator using
the format:
```
ESC]7;file://hostname/path BEL
```
This enables the terminal to track the current directory without manual
commands, providing better context for AI features and ensuring accurate
path information.
## Implementation Details
### Fish Shell (`fish_wavefish.sh`)
Added shell integration functions using Fish-native features:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
using `set -q` and `string match -q`
- `_waveterm_si_osc7()` - Sends the OSC 7 sequence with built-in URL
encoding
- Uses `string escape --style=url` for UTF-8 percent-encoding
- Hooked to `fish_prompt` event and `PWD` variable changes for automatic
updates
**Key Features:**
- Fish-native checks (`set -q`, `string match`) instead of non-portable
`test -o`
- Built-in `string escape --style=url` for proper UTF-8 percent-encoding
- Simple, portable, and maintainable (32 lines total)
### PowerShell (`pwsh_wavepwsh.sh`)
Added simplified shell integration that leverages frontend
normalization:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
- `_waveterm_si_osc7()` - Sends OSC 7 with raw path encoding
- Uses `[System.Uri]::EscapeDataString()` for proper percent-encoding
- Integrated into the prompt function while preserving existing prompts
**Key Features:**
- **No path rewriting**: Sends raw paths (e.g., `C:\Users\Name` →
`C%3A%5CUsers%5CName`)
- **UNC support**: Network paths like `\\server\share` encoded as
`%5C%5Cserver%5Cshare`
- **Hostname fallback**: `$env:COMPUTERNAME` → `$env:HOSTNAME` → empty
(produces `file:///path`)
- **No DNS lookup**: Avoids potentially slow DNS calls
- Simple and efficient (53 lines total)
## Implementation Benefits
Both implementations use native, built-in features for maximum
compatibility and maintainability:
**Fish:**
- ✅ Replaced `test -o` with fish-native `set -q` and `string match -q`
for better portability
- ✅ Replaced manual string replacements with `string escape --style=url`
for proper UTF-8 support
- ✅ Removed custom URL encoding function (19 lines removed)
**PowerShell:**
- ✅ Uses built-in `[System.Uri]::EscapeDataString()` for proper
percent-encoding
- ✅ No path rewriting - frontend handles normalization via
`decodeURIComponent()` and backslash conversion
- ✅ Proper UNC path support without special-casing
- ✅ Removed DNS lookup to avoid slow operations
- ✅ Removed custom URL encoding function
## Testing
All implementations were tested for:
- ✅ URL encoding of special characters (spaces, #, ?, &, ;, +, %)
- ✅ Correct OSC 7 format generation
- ✅ Fish-native checks work correctly (TMUX, STY, TERM patterns)
- ✅ Raw path encoding (PowerShell - no rewriting)
- ✅ UNC path support (PowerShell)
- ✅ Unix path handling
- ✅ Go package compilation
- ✅ No security issues (CodeQL)
## Path Handling Examples
**Fish:**
- `/home/user` → `/home/user`
- `/path with spaces` → `/path%20with%20spaces`
- `/file#hash` → `/file%23hash`
**PowerShell:**
- Windows: `C:\Users\Name` → `file://HOST/C%3A%5CUsers%5CName`
- UNC: `\\server\share\folder` →
`file://HOST/%5C%5Cserver%5Cshare%5Cfolder`
- Empty hostname: produces `file:///path` format
## Files Changed
- `pkg/util/shellutil/shellintegration/fish_wavefish.sh` (+22 lines, -18
lines = net +4 lines, but 19 lines of custom code removed)
- `pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh` (+26 lines, -51
lines = net -25 lines)
Total: 38 fewer lines of code with better functionality and
maintainability.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2025-10-18 00:23:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function _waveterm_si_prompt --on-event fish_prompt
|
2025-10-21 00:29:38 +00:00
|
|
|
set -l _waveterm_si_status $status
|
|
|
|
|
_waveterm_si_blocked; and return
|
|
|
|
|
if test $_WAVETERM_SI_FIRSTPROMPT -eq 1
|
|
|
|
|
set -l uname_info (uname -smr 2>/dev/null)
|
|
|
|
|
printf '\033]16162;M;{"shell":"fish","shellversion":"%s","uname":"%s","integration":true}\007' $FISH_VERSION "$uname_info"
|
|
|
|
|
# OSC 7 only sent on first prompt - chpwd hook handles directory changes
|
|
|
|
|
_waveterm_si_osc7
|
|
|
|
|
else
|
|
|
|
|
printf '\033]16162;D;{"exitcode":%d}\007' $_waveterm_si_status
|
|
|
|
|
end
|
|
|
|
|
printf '\033]16162;A\007'
|
|
|
|
|
set -g _WAVETERM_SI_FIRSTPROMPT 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function _waveterm_si_preexec --on-event fish_preexec
|
|
|
|
|
_waveterm_si_blocked; and return
|
|
|
|
|
set -l cmd (string join -- ' ' $argv)
|
|
|
|
|
set -l cmd_length (string length -- "$cmd")
|
|
|
|
|
if test $cmd_length -gt 8192
|
|
|
|
|
set -l cmd64 (printf '# command too large (%d bytes)' $cmd_length | base64 2>/dev/null | string replace -a '\n' '' | string replace -a '\r' '')
|
|
|
|
|
printf '\033]16162;C;{"cmd64":"%s"}\007' "$cmd64"
|
|
|
|
|
else
|
|
|
|
|
set -l cmd64 (printf '%s' "$cmd" | base64 2>/dev/null | string replace -a '\n' '' | string replace -a '\r' '')
|
|
|
|
|
if test -n "$cmd64"
|
|
|
|
|
printf '\033]16162;C;{"cmd64":"%s"}\007' "$cmd64"
|
|
|
|
|
else
|
|
|
|
|
printf '\033]16162;C\007'
|
|
|
|
|
end
|
|
|
|
|
end
|
Add OSC 7 support for Fish and PowerShell shells (#2456)
## Overview
This PR implements OSC 7 (current working directory reporting) support
for Fish shell and PowerShell, completing the shell integration coverage
alongside the existing Bash and Zsh implementations added in #2444.
## What is OSC 7?
OSC 7 is an operating system command that allows shells to automatically
report their current working directory to the terminal emulator using
the format:
```
ESC]7;file://hostname/path BEL
```
This enables the terminal to track the current directory without manual
commands, providing better context for AI features and ensuring accurate
path information.
## Implementation Details
### Fish Shell (`fish_wavefish.sh`)
Added shell integration functions using Fish-native features:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
using `set -q` and `string match -q`
- `_waveterm_si_osc7()` - Sends the OSC 7 sequence with built-in URL
encoding
- Uses `string escape --style=url` for UTF-8 percent-encoding
- Hooked to `fish_prompt` event and `PWD` variable changes for automatic
updates
**Key Features:**
- Fish-native checks (`set -q`, `string match`) instead of non-portable
`test -o`
- Built-in `string escape --style=url` for proper UTF-8 percent-encoding
- Simple, portable, and maintainable (32 lines total)
### PowerShell (`pwsh_wavepwsh.sh`)
Added simplified shell integration that leverages frontend
normalization:
- `_waveterm_si_blocked()` - Prevents OSC 7 in tmux/screen environments
- `_waveterm_si_osc7()` - Sends OSC 7 with raw path encoding
- Uses `[System.Uri]::EscapeDataString()` for proper percent-encoding
- Integrated into the prompt function while preserving existing prompts
**Key Features:**
- **No path rewriting**: Sends raw paths (e.g., `C:\Users\Name` →
`C%3A%5CUsers%5CName`)
- **UNC support**: Network paths like `\\server\share` encoded as
`%5C%5Cserver%5Cshare`
- **Hostname fallback**: `$env:COMPUTERNAME` → `$env:HOSTNAME` → empty
(produces `file:///path`)
- **No DNS lookup**: Avoids potentially slow DNS calls
- Simple and efficient (53 lines total)
## Implementation Benefits
Both implementations use native, built-in features for maximum
compatibility and maintainability:
**Fish:**
- ✅ Replaced `test -o` with fish-native `set -q` and `string match -q`
for better portability
- ✅ Replaced manual string replacements with `string escape --style=url`
for proper UTF-8 support
- ✅ Removed custom URL encoding function (19 lines removed)
**PowerShell:**
- ✅ Uses built-in `[System.Uri]::EscapeDataString()` for proper
percent-encoding
- ✅ No path rewriting - frontend handles normalization via
`decodeURIComponent()` and backslash conversion
- ✅ Proper UNC path support without special-casing
- ✅ Removed DNS lookup to avoid slow operations
- ✅ Removed custom URL encoding function
## Testing
All implementations were tested for:
- ✅ URL encoding of special characters (spaces, #, ?, &, ;, +, %)
- ✅ Correct OSC 7 format generation
- ✅ Fish-native checks work correctly (TMUX, STY, TERM patterns)
- ✅ Raw path encoding (PowerShell - no rewriting)
- ✅ UNC path support (PowerShell)
- ✅ Unix path handling
- ✅ Go package compilation
- ✅ No security issues (CodeQL)
## Path Handling Examples
**Fish:**
- `/home/user` → `/home/user`
- `/path with spaces` → `/path%20with%20spaces`
- `/file#hash` → `/file%23hash`
**PowerShell:**
- Windows: `C:\Users\Name` → `file://HOST/C%3A%5CUsers%5CName`
- UNC: `\\server\share\folder` →
`file://HOST/%5C%5Cserver%5Cshare%5Cfolder`
- Empty hostname: produces `file:///path` format
## Files Changed
- `pkg/util/shellutil/shellintegration/fish_wavefish.sh` (+22 lines, -18
lines = net +4 lines, but 19 lines of custom code removed)
- `pkg/util/shellutil/shellintegration/pwsh_wavepwsh.sh` (+26 lines, -51
lines = net -25 lines)
Total: 38 fewer lines of code with better functionality and
maintainability.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2025-10-18 00:23:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Also update on directory change
|
|
|
|
|
function _waveterm_si_chpwd --on-variable PWD
|
|
|
|
|
_waveterm_si_osc7
|
|
|
|
|
end
|