ayoisaiah / f2

F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!
https://f2.freshman.tech
MIT License
866 stars 38 forks source link

Wrong input when piping from fd #78

Closed david-askari closed 3 months ago

david-askari commented 3 months ago

Tick this box to confirm you have reviewed the above.

What version of F2 are you using?

1.9.1

How did you install F2?

apt with Debian Bookworm packages

What operating system are you using F2 on?

Debian 12 'Bookworm'

Describe your bug.

When using fd as input pipe to f2, direct piping does not working as expected. Piping instead into xargs with f2 results in the expected behaviour.

What are the steps to reproduce the behavior?

~
❯ mkdir test && cd test
mkdir: created directory 'test'

~/test
❯ touch foo

~/test
❯ touch bar

~/test
❯ fd 'foo' | f2 -r '{f}'
*——————————*—————————*————————*
| ORIGINAL | RENAMED | STATUS |
*——————————*—————————*————————*
| bar      | bar     |        |
| foo      | foo     |        |
*——————————*—————————*————————*
 DRY RUN  Commit the above changes with the -x/--exec flag

~/test
❯ fd 'foo' | xargs f2 -r '{f}'
*——————————*—————————*————————*
| ORIGINAL | RENAMED | STATUS |
*——————————*—————————*————————*
| foo      | foo     |        |
*——————————*—————————*————————*
 DRY RUN  Commit the above changes with the -x/--exec flag

~/test
❯

What behaviour did you observe?

When piping from fd directly into f2, the input is foo and bar. Although fd returns only foo.

What is the expected behaviour?

f2 should process foo only.

hotgar commented 3 months ago

Looks like right now using stdin doesn't populate ctx so f2 just defaults to processing the whole current directory. xargs works because it just puts the string at the end of f2 command.

ayoisaiah commented 3 months ago

Thanks for reporting this! I've already fixed it locally, just need to add some tests:

image

ayoisaiah commented 3 months ago

https://github.com/ayoisaiah/f2/commit/4957f29839a9a30c9576f493f1b8bc45fec35b14