bulletmark / edir

Program to rename, remove, and copy files and directories using your editor
139 stars 8 forks source link

creating new empty files and directories #23

Closed balta2ar closed 4 months ago

balta2ar commented 4 months ago

I wonder if it could also be useful to be able to create empty files and directories. Let's say we have two dirs before we edit: "1" and "2". After editing we get:

1  ./1/
2  ./2/
new/file
new/dir/

"new file" functionality could be worked around by creating an empty file before starting edir, and then copying it though, but that's an extra step.

bulletmark commented 4 months ago

It's not clear what you are asking for here? What is that output above? You have numbers on the first two lines so that implies it is what you are seeing in your editor, but then what are the other two lines?

Note, as I say in the last paragraph of section 2 of the README, it can get too complicated and confusing if you try to accommodate tricky renames and/or copies across different directories.

balta2ar commented 4 months ago

Sorry, my phrasing indeed could have been more clear :slightly_smiling_face: I showed the state of the editor after I invoked edir AND added 2 lines manually:

1  ./1/      <-- this line/directory already existed when I invoked edir
2  ./2/      <-- this one too
new/file     <-- this is a manually added line, which means I'd like edir to create an empty file with that path
new/dir/     <-- also something I typed manually, but this should be a directory

so basically I was wondering if a new syntax could be added that would allow creating empty files and directories right from edir -- not necessarily the syntax I suggested though. I totally agree it could get complicated, for example conflicts could occur if we do this:

1  ./1/
2  ./2/
new/file
new/file/

it's not clear if I want to create a file or a directory. maybe it should be an error? or maybe just plainly execute what the user instructed?

I saw that it was possible with other tools (https://github.com/stevearc/oil.nvim) but I've mostly used vidir so far, which doesn't support it. Now when I discovered edir, I thought I'd suggest that idea in case you'd be interested :slightly_smiling_face:

bulletmark commented 4 months ago

Sorry, I don't think this is a good idea.

  1. It breaks the current convention that every line must start with a number. Currently edir checks that all lines start with a valid number and immediately reports an error with the edited file if any don't. This proposal would eliminate any error checking so if the user leaves junk in the file then it will just get created as a new file/dir.
  2. Presently the semantics are simple and obvious: delete a numbered line to delete, change a line to rename, copy a line to copy. This proposed change breaks that simplicity.
  3. It is very rare I want to create a new empty file. If I do then I usetouch which is just as efficient as this proposal. E.g. touch afile or echo some words >afile and then use edir to copy afile N times.

edir is not intended to be a file manager. Use ranger etc for that (and use the edir plugin with it).

bulletmark commented 4 months ago

Just released version 2.29 with this change.