fd icon indicating copy to clipboard operation
fd copied to clipboard

Unexpected behavior for the Placeholder syntax on windows powershell

Open g-berthiaume opened this issue 3 years ago • 3 comments

What version of fd are you using?

$ fd --version
fd 8.2.1

Context I want to list all files recursively in a directory while printing only the basename.

So instead of this:

dir1\test1.txt
dir1\test2.txt
dir2\testA.txt

I want this:

test1.txt
test2.txt
testA.txt

To my understanding, the best way to do so is to use fd -t f -x echo {/}.

On windows cmd.exe it works fine (but it's very slow).

fd -t f -x echo {/}
test1.txt
test2.txt
testA.txt

On windows powershell.exe, the output is not as expected.

$ fd -t f -x echo {/}
-encodedCommand LwA= -inputFormat xml -outputFormat text dir1\test1.txt
-encodedCommand LwA= -inputFormat xml -outputFormat text dir1\test2.txt
-encodedCommand LwA= -inputFormat xml -outputFormat text dir2\testA.txt

Question Is this a bug? Maybe a documentation problem? Is there a better way than fd -t f -x echo {/} ?

g-berthiaume avatar Mar 02 '21 20:03 g-berthiaume

Question Is this a bug?

I don't think so. You need to properly escape {} characters. Please see #646, #722, #310 for more details.

Maybe a documentation problem?

Possibly. It's not really fds fault. {} always need to be escaped in PowerShell. But we could maybe make sure that all examples use a syntax that would also work in PowerShell and mention it in the troubleshooting section here: https://github.com/sharkdp/fd#troubleshooting

Is there a better way than fd -t f -x echo {/} ?

Not really. Alternatively, you could use -x basename, if that's available on Windows.

sharkdp avatar Mar 02 '21 20:03 sharkdp

Hi @sharkdp, Thanks for your feedback and sorry for the duplication.

Is there a better way than fd -t f -x echo {/} ?

Not really

Yeah, this is what I thought. Not sure why it's so slow though. Have a good day and thanks for fd; it's a joy to use.

g-berthiaume avatar Mar 03 '21 13:03 g-berthiaume

I am reopening this to make sure this will be updated in the documentation.

sharkdp avatar Mar 14 '21 19:03 sharkdp