kelleyma49 / PSFzf

A PowerShell wrapper around the fuzzy finder fzf
MIT License
787 stars 34 forks source link

Invoke-FuzzyEdit - Bad Path If `-Directory` Used #99

Closed mattcargile closed 2 years ago

mattcargile commented 2 years ago

Description

Using fd.exe which returns relative paths as opposed to dir /B /S which returns the full name, the code below can return a path like C:\my path\".\myfile.txt" from Join-Path. https://github.com/kelleyma49/PSFzf/blob/0843f35b0e77101f0718e89bb075e20e4e211d23/PSFzf.Functions.ps1#L71

To Reproduce

mkdir 'test folder'
ni '.\test folder\file.txt'
ni '.\test folder\file2.txt'
Invoke-FuzzyEdit '.\test folder\'

Behavior

In VS Code the file test and file.txt are created that don't exist. image

Module Version

2.3.1-alpha

Shell

PowerShell 7.2.1

Reference Issue

issue.

mattcargile commented 2 years ago

Maybe this function could be utilized?

See main post. This comment is no longer as relevant.

https://github.com/kelleyma49/PSFzf/blob/0843f35b0e77101f0718e89bb075e20e4e211d23/PSFzf.Base.ps1#L77-L84

mattcargile commented 2 years ago

So fd.exe has an --absolute-path that could be used to mimic the output of dir /B /S. It doesn't appear there is a flag on dir to output the relative path.

Then this code could be changed.

https://github.com/kelleyma49/PSFzf/blob/0843f35b0e77101f0718e89bb075e20e4e211d23/PSFzf.Functions.ps1#L68-L75

to something like

        $fileList = $files -join ' '

Then we could add a -PathType or the like to Get-FileSystemCmd

Those are my ideas. Not sure what you think @kelleyma49?

mattcargile commented 2 years ago

Working on the Get-FileSystemCmd, I'm not sure how we can tell if the user is using fd.exe easily in their FZF_DEFAULT_COMMAND. A user could conceivably pipe a command line tool into fd.exe in this variable. This would make a pattern match like 'fd*' maybe not as accurate.

Like on this line.

https://github.com/kelleyma49/PSFzf/blob/0843f35b0e77101f0718e89bb075e20e4e211d23/PSFzf.Base.ps1#L49

Should we be adding the --absolute-path here anyway. I would prefer it that way because usually I don't want the full path in my fzf output.