elihunter173 / dirbuf.nvim

A file manager for Neovim which lets you edit your filesystem like you edit text
GNU Affero General Public License v3.0
423 stars 7 forks source link

Feature request: Create nested directories #3

Open seblj opened 2 years ago

seblj commented 2 years ago

First of all, I think this plugin looks really cool, and I really like the intuitive way to create, delete and copy file/directory!

I have a feature request to be able to create nested directories. For example: foo/bar/baz/

I would want this to create a directory foo containing another directory bar, containing another directory baz.

Also, I think it would be nice if a file could be created inside a nested directory as well.

For example: foo/bar/baz

I would want this to create a directory foo containing a directory bar, containing a file baz.

This, along with the feature for mv (which I saw already was requested on reddit) would be really awesome to have!

Thanks!

elihunter173 commented 2 years ago

Thanks! I'm glad you like it.

This is a good idea. The concern I have with it is what happens if someone already has a directory foo/ and appends bar to it. That is you have a directory buffer like

foo/    #deadbeef

and edit it to be

foo/bar #deadbeef

Under dirbuf's current semantics this essentially becomes mv foo/ foo/bar which doesn't work, but I think it's fairly obvious that the user really wanted to create a file bar in foo/ (i.e. touch foo/bar). Under dirbufs current semantics that would be

foo/    #deadbeef
foo/bar

Maybe the best choice would be to issue a specific error message (better than the generic Move failed for foo -> foo/bar: EINVAL: invalid argument: foo -> foo/bar), but last time I tried implementing this I got stuck on trying to come up with clear semantics that made the first edit valid without making dirbuf too magical.

seblj commented 2 years ago

Ah yes, I understand your concern. I think it would be nice if a file could be added like that, but as you say, it probably makes things more complex. For me at least, I would't mind if it only works if the directory foo doesn't already exist

elihunter173 commented 2 years ago

Sorry about the edit noise. I've been revisiting these old feature requests to take a stab at implementing them.

I think my previous concern about making foo/bar valid is a small fry where Dirbuf errors and users can quickly learn and hopefully intuit why that's false. I think your solution of having creating a new file automatically create the nested directories as necessary is perfect