Skip to content

Commit

Permalink
Mitigate #236 (#239)
Browse files Browse the repository at this point in the history
- Add path used to filter selections to results
  • Loading branch information
kelleyma49 authored Dec 19, 2023
1 parent 57029c7 commit b79c3e1
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions PSFzf.Base.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -693,45 +693,46 @@ function Invoke-FzfPsReadlineHandlerProvider {
if ([String]::IsNullOrWhitespace($currentPath) -or !(Test-Path $currentPath)) {
$currentPath = $PWD
}
$isUsingPath = -not [string]::IsNullOrWhiteSpace($currentPath)

$result = @()
try
{
$result = @()
try {
$script:OverrideFzfDefaults = [FzfDefaultOpts]::new($env:FZF_CTRL_T_OPTS)

if (-not [System.String]::IsNullOrWhiteSpace($env:FZF_CTRL_T_COMMAND)) {
Invoke-Expression ($env:FZF_CTRL_T_COMMAND) | Invoke-Fzf -Multi | ForEach-Object { $result += $_ }
} else {
if ([string]::IsNullOrWhiteSpace($currentPath)) {
}
else {
if (-not $isUsingPath) {
Invoke-Fzf -Multi | ForEach-Object { $result += $_ }
} else {
}
else {
$resolvedPath = Resolve-Path $currentPath -ErrorAction SilentlyContinue
$providerName = $null
if ($null -ne $resolvedPath) {
$providerName = $resolvedPath.Provider.Name
}
switch ($providerName) {
# Get-ChildItem is way too slow - we optimize using our own function for calling fzf directly (Invoke-FzfDefaultSystem):
'FileSystem' {
'FileSystem' {
if (-not $script:UseFd) {
$result = Invoke-FzfDefaultSystem $resolvedPath.ProviderPath '--multi'
} else {
}
else {
Invoke-Expression (Get-FileSystemCmd $resolvedPath.ProviderPath) | Invoke-Fzf -Multi | ForEach-Object { $result += $_ }
}
}
'Registry' { Get-ChildItem $currentPath -Recurse -ErrorAction SilentlyContinue | Select-Object Name -ExpandProperty Name | Invoke-Fzf -Multi | ForEach-Object { $result += $_ } }
$null { Get-ChildItem $currentPath -Recurse -ErrorAction SilentlyContinue | Select-Object FullName -ExpandProperty FullName | Invoke-Fzf -Multi | ForEach-Object { $result += $_ } }
Default {}
'Registry' { Get-ChildItem $currentPath -Recurse -ErrorAction SilentlyContinue | Select-Object Name -ExpandProperty Name | Invoke-Fzf -Multi | ForEach-Object { $result += $_ } }
$null { Get-ChildItem $currentPath -Recurse -ErrorAction SilentlyContinue | Select-Object FullName -ExpandProperty FullName | Invoke-Fzf -Multi | ForEach-Object { $result += $_ } }
Default {}
}
}
}
}
catch
{
# catch custom exception
}
finally
{
catch {
# catch custom exception
}
finally {
if ($script:OverrideFzfDefaults) {
$script:OverrideFzfDefaults.Restore()
$script:OverrideFzfDefaults = $null
Expand All @@ -743,10 +744,20 @@ function Invoke-FzfPsReadlineHandlerProvider {
if ($null -ne $result) {
# quote strings if we need to:
if ($result -is [system.array]) {
for ($i = 0;$i -lt $result.Length;$i++) {
$result[$i] = FixCompletionResult $result[$i]
for ($i = 0; $i -lt $result.Length; $i++) {
if ($isUsingPath) {
$resultFull = Join-Path $currentPath $result[$i]
}
else {
$resultFull = $result[$i]
}
$result[$i] = FixCompletionResult $resultFull
}
}
else {
if ($isUsingPath) {
$result = Join-Path $currentPath $result
}
} else {
$result = FixCompletionResult $result
}

Expand Down

0 comments on commit b79c3e1

Please sign in to comment.