marcusbuffett / pipe-rename

Rename your files using your favorite text editor
https://crates.io/crates/pipe-rename
MIT License
397 stars 12 forks source link

Can't pipe file names to pipe-rename without -y #65

Open CptPotato opened 1 year ago

CptPotato commented 1 year ago

I've ran into an issue when piping file names into rename. The editor opens correctly, but after closing it the program immediately exits at the prompt:

Execute these renames?:
> Yes
  No
  Edit
  Reset
Error: Incorrect function. (os error 1)
error: process didn't exit successfully: `target\debug\renamer.exe` (exit code: 1)

Running in debug mode didn't provide a stack trace but it looks like it's the call to dialoguer::prompts::select::Select. Using -y to skip the prompt works as an alternative. I'm using Windows if that makes a difference.

Also, thanks for this cool tool :+1:

mtimkovich commented 1 year ago

Thanks for the report! It seems Windows-specific due to the Incorrect function error. What shell are you using? I'm worried this might be a dialoguer bug.

@assarbad have you been encountering this problem?

Edit: Seems like dialoguer doesn't work with Cygwin or GitBash. It does work with cmd.exe and Powershell however.

CptPotato commented 1 year ago

Yes, this might be a dialoguer issue.

What shell are you using?

I'm using regular Cmd. Powershell has the same behavior, Git bash (launched from Cmd or using mingw64) is no different.

For now I've worked around the issue by patching in glob support. I mostly used something like this fd -g **/*.exr | renamer which I can do without piping now (renamer **/*.exr).

assarbad commented 1 year ago

@mtimkovich I have not, but I am trying to avoid using it in piped mode. I think the issue, albeit on Windows, is the same as we have seen on other platforms.

I have been investigating reopening /dev/tty from within renamer, but that's also a Unix-only solution to the best of my understanding.

@CptPotato feel like sharing (or contributing by way of a PR) the patch? Basic globbing support is included now on Windows, but indeed the full breadth of what various shells provide may not be covered by it (such as **/*.exr).

CptPotato commented 1 year ago

@CptPotato feel like sharing (or contributing by way of a PR) the patch? Basic globbing support is included now on Windows, but indeed the full breadth of what various shells provide may not be covered by it (such as **/*.exr).

Sure! I'll have to clean it up a little but I can create a PR soon.

CptPotato commented 1 year ago

Sorry this went way under the radar for me. I can't seem to reproduce the issue I had with **/*.exr on my new machine :confused:. It looks like the pattern is correctly expanded by the shell or something since opts.files already contains all the paths now.

Either way, in case you're interested here's the diff: https://github.com/marcusbuffett/pipe-rename/compare/master...CptPotato:pipe-rename:glob