jarun / nnn

n³ The unorthodox terminal file manager
BSD 2-Clause "Simplified" License
19.43k stars 765 forks source link

batch rename find/fd files #1214

Closed ixzh closed 3 years ago

ixzh commented 3 years ago

Is your feature request related to a problem? Please describe.

fd pdf ~/Downloads -0 | nnn can be used to show and open files, but batch rename r doesn't work.

Describe the solution you'd like

Would it be possible to make r operate on symlink list to rename target files? seems to be a natural extension of the r function.

jarun commented 3 years ago

Press Left on the symlink and it will take you to the target file. Then rename it.

ixzh commented 3 years ago

Press Left on the symlink and it will take you to the target file. Then rename it.

That's good for an individual file. But if there are hundreds of files from different folders, rename them one by one is tedious. Use find to filter the list and batch rename accordingly is more practical I think.

jarun commented 3 years ago

While it's a regular use case for you, implementing it is roundabout - we have to find each target, add to a new buffer and then rename. Sorry, there is no ROI for us here.

ixzh commented 3 years ago

Thanks anyway!

N-R-K commented 3 years ago

@ixzh this use-case maybe better solved by some dedicated batch-ranamer script/program. There are quite a lot out there, although I haven't used any.

ixzh commented 3 years ago

@ixzh this use-case maybe better solved by some dedicated batch-ranamer script/program. There are quite a lot out there, although I haven't used any.

you mean in the plugin listing? Or where can I find? I'm using the default scripts/.nmv.

N-R-K commented 3 years ago

you mean in the plugin listing?

No, independent ones.

Or where can I find?

You can try searching for "batch renamer" in github. As I've said, I don't use any so I can't recommend one.

ixzh commented 3 years ago

you mean in the plugin listing?

No, independent ones.

Or where can I find?

You can try searching for "batch renamer" in github. As I've said, I don't use any so I can't recommend one.

Ok, thank you! I will try to figure out a way.

jarun commented 3 years ago

On second thoughts, @KlzXS do you think we can extend the batchrename script to rename the files in the current directory but apply to the symlink targets? We can see if we can figure a way to indicate to the script if this is a case of a listed directory.

jarun commented 3 years ago

If someone else wants to give it a try, we will need to rename the target for the symlink in plugin .nmv rather than the file itself to achieve this.

The main program can set an env var before calling .nmv to indicate that the current directory is in listing mode.

KlzXS commented 3 years ago

We can do that. Make .nmv resolve symlinks if. Suggest a name for the env variable.

jarun commented 3 years ago

$NNN_LIST

jarun commented 3 years ago

Resolved at commit 470c777f2d50f21f817b89129c0ee89b8a3b3a35.

@ixzh please confirm the fix.

jarun commented 3 years ago

Please test with commit eb769c0de5d762280b2bd973e3024890c884a58e as I have made a minor modification.

ixzh commented 3 years ago

Thank you for the workout!! I have tested the following, and the files are missing after renaming their symbolic links in list mode:

  1. I put 3 files in the following place image

  2. and start nnn using fd . ~/Downloads/Telegram\ Desktop/ -0 | nnn image

  3. and r batch rename by prepending a number in Vim image becomes: image

  4. and :wq, the listing now shows 3 files and 3 symbolic links image

  5. pressing q, and the target files are gone. image

I also tried fd . ~/Downloads/Telegram\ Desktop/ -0 | NNN_LIST=1 nnn in step 2, same result.

So are the files removed from disk by doing the above? I can't locate them in my system.

Another issue: the getplugs plugin seems to download an outdated zip.

KlzXS commented 3 years ago

the getplugs plugin seems to download an outdated zip

By default it downloads a zip that goes with the version of nnn. To download from master run it as getplugs master.

ixzh commented 3 years ago

the getplugs plugin seems to download an outdated zip

By default it downloads a zip that goes with the version of nnn. To download from master run it as getplugs master.

I see. I'll amend my plugin command. Thanks!

KlzXS commented 3 years ago

I can see where the problem is. For now use it only with selection.

ixzh commented 3 years ago

hey since commit #1508874, .nmv seems not to work for 'c'urrent : image

I changed the leading 0s to .s, also can't save the changes.

jarun commented 3 years ago

@KlzXS can you please take a look?

KlzXS commented 3 years ago

See #1232. I hope this ends the whole saga.

ixzh commented 3 years ago

thank you! it works.