Skip to content

api.fs.create_directory #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thepenguinthatwants opened this issue Apr 12, 2021 · 10 comments · Fixed by #2572
Closed

api.fs.create_directory #285

thepenguinthatwants opened this issue Apr 12, 2021 · 10 comments · Fixed by #2572
Labels
API API or Event PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated

Comments

@thepenguinthatwants
Copy link

Right now

  • type 'a' to add a file

Could be nice if

  • type 'A' to add a folder
@kyazdani42
Copy link
Member

type a and then add a trailing / will create folders (see #3).
If you really want a command to do that, please reopen this :)

@twiddli
Copy link

twiddli commented Apr 16, 2023

Hi, great plugin but I think this is a bit unintuitive for new people (like me).
It would be great to have a dedicated command for it as well. That would at least save people from having to google.

I have been trying to match Vim's default file explorer's keymappings and would really like to dedicate d to creating folders.

@alex-courtis alex-courtis changed the title Feature request, creating folder by keybinding api.fs.create directory option Apr 17, 2023
@alex-courtis alex-courtis added PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated API API or Event labels Apr 17, 2023
@alex-courtis
Copy link
Member

alex-courtis commented Apr 17, 2023

We can do this. Something like:

fs.create_directory({node})              *nvim-tree-api.fs.create_directory()*
    Prompt to create a directory.

    Parameters: ~{node} (Node) parent, uses the parent of a file.

@alex-courtis alex-courtis reopened this Apr 17, 2023
@alex-courtis alex-courtis changed the title api.fs.create directory option api.fs.create_directory Apr 17, 2023
@gegoune
Copy link
Collaborator

gegoune commented Apr 17, 2023

On Unix systems directory is just a type of node, same as file. Should we make it more generic, like create_node?

@alex-courtis
Copy link
Member

On Unix systems directory is just a type of node, same as file. Should we make it more generic, like create_node?

Yes. We could be more generic and extend the existing create like:

fs.create({node}, {opts})                          *nvim-tree-api.fs.create()*
    Prompt to create a file or directory. Use a trailing `/` for a directory.

    Parameters: ~{node} (Node) parent, uses the parent of a file.
      • {opts} (table) optional parameters

    Options: ~{type} (string) `"file"` or `"directory"`, default `"file"`

Only problem is how we would pass those opts in, with the node populated. Passing nil would work, we'd need to note it in the doc.

@alex-courtis
Copy link
Member

If I were designing the API from scratch today, I'd make the {node} optional parameters for all such functions. Node really optional.

e.g.

fs.create({opts})                                  *nvim-tree-api.fs.create()*
    Prompt to create a file or directory. Use a trailing `/` for a directory.

    Parameters: ~{opts} (table) optional parameters

    Options: ~{node} (Node) default node under cursor
      • {type} (string) `"file"` or `"directory"`, default `"file"`

The problem is backwards compatibility. It was achieved for functions like ApiTreeToggleOpts via looking at parameter types. We can't do that in this case as node and opts are both tables.

One option is to look for fields like absolute_path, fs_stat etc. in the table parameter, to determine whether it is a node or opts. Not a great solution.

@alex-courtis
Copy link
Member

Created #2146

@alex-courtis
Copy link
Member

alex-courtis commented Dec 3, 2023

We have a functional workflow for adding directories via the trailing /.

I'm not seeing much value here...

@gegoune ?

@gegoune
Copy link
Collaborator

gegoune commented Dec 3, 2023

Personally I am not that bothered either. / suffix is what I use every time I need to create directory.

This is an old issue that Kiyan closed promptly. Also premise that "That would at least save people from having to google." isn't entirely true if documentation is provided with plugin itself (it is).

@alex-courtis
Copy link
Member

Added FAQ: https://github.com/nvim-tree/nvim-tree.lua/wiki/FAQ

Clarified: #2572

alex-courtis added a commit that referenced this issue Dec 4, 2023
docs(#285): clarify api.fs.create directory creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API or Event PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants