mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 19:07:17 +00:00
* feat(terminal): support Directory Picker in Windows PowerShell * fix(terminal): handle qualified PowerShell paths and CI fixtures * test(plugins): await dialog focus restoration in log settings * test(terminal): normalize Windows fixture paths with native realpath * fix(terminal): retry stale listings and recognize spaced UNC shares --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
47 lines
1.9 KiB
PowerShell
47 lines
1.9 KiB
PowerShell
# Session-only integration honors the current execution policy and preserves
|
|
# user-managed profile, registry and PSReadLine settings.
|
|
if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage') { return }
|
|
if (Test-Path variable:global:__NetcattyDirectory) { return }
|
|
if (-not $env:NETCATTY_DIRECTORY_NONCE) { return }
|
|
|
|
$global:__NetcattyDirectory = @{
|
|
OriginalPrompt = $function:prompt
|
|
Nonce = $env:NETCATTY_DIRECTORY_NONCE
|
|
Sequence = 0
|
|
}
|
|
$env:NETCATTY_DIRECTORY_NONCE = $null
|
|
|
|
function global:prompt {
|
|
$netcattyFailed = -not $global:?
|
|
Set-StrictMode -Off
|
|
$netcattyExitCode = $global:LASTEXITCODE
|
|
$netcattyReport = ''
|
|
try {
|
|
$global:__NetcattyDirectory.Sequence++
|
|
$netcattyLocation = $ExecutionContext.SessionState.Path.CurrentLocation
|
|
$netcattyPath = $null
|
|
if ($netcattyLocation.Provider.Name -eq 'FileSystem') {
|
|
$netcattyPath = $netcattyLocation.ProviderPath
|
|
}
|
|
$netcattyState = @{
|
|
version = 1
|
|
nonce = $global:__NetcattyDirectory.Nonce
|
|
pid = $PID
|
|
sequence = $global:__NetcattyDirectory.Sequence
|
|
provider = $netcattyLocation.Provider.Name
|
|
cwd = $netcattyPath
|
|
home = $HOME
|
|
} | Microsoft.PowerShell.Utility\ConvertTo-Json -Compress
|
|
$netcattyEncoded = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($netcattyState))
|
|
$netcattyReport = "$([char]27)]633;P;NetcattyDirectory=$netcattyEncoded$([char]7)"
|
|
} catch {
|
|
# Prompt remains usable if reporting fails.
|
|
}
|
|
$global:LASTEXITCODE = $netcattyExitCode
|
|
# Restore the status seen by the original prompt (also on PowerShell 5.1).
|
|
if ($netcattyFailed) { Microsoft.PowerShell.Utility\Write-Error 'failure' -ErrorAction Ignore }
|
|
$netcattyPrompt = $global:__NetcattyDirectory.OriginalPrompt.Invoke()
|
|
$global:LASTEXITCODE = $netcattyExitCode
|
|
return $netcattyReport + ($netcattyPrompt -join '')
|
|
}
|