Skip to content
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

Ability to create multiple files and / or directories in 1 command #302

Open
nickjj opened this issue Feb 23, 2021 · 14 comments
Open

Ability to create multiple files and / or directories in 1 command #302

nickjj opened this issue Feb 23, 2021 · 14 comments
Labels
discussion enhancement New feature or request

Comments

@nickjj
Copy link

nickjj commented Feb 23, 2021

I find myself creating directories and files using Fern because it's handy, but I noticed that you can't create more than 1 file or directory at a time in a way that produces an expected result.

For example if you create a new path and enter in a/ b/ you end up with a/b (B is nested in A) instead of a/ b/ (they are their own independent directories). The expected outcome would be what you'd get if you used mkdir or touch directly.

To get around this I find myself running :!mkdir a/ b/ in Vim directly which works but this also means a lot more typing (especially if it's a nested directory in a project) and also reloading Fern to pick up the changes.

@lambdalisue
Copy link
Owner

For example if you create a new path and enter in a/ b/ you end up with a/b (B is nested in A) instead of a/ b/ (they are their own independent directories). The expected outcome would be what you'd get if you used mkdir or touch directly.

No. It's a bit incorrect. Fern creates a/ b/ rather than a/b/ for a/ b/ thus users get the result as-is. I didn't designed the feature to mimic the behavior of mkdir or touch.

I understand your want but I cannot image a good interface which consistent with the current one (I'm not going to apply breaking changes for this.) Does anyone have ideas?

@lambdalisue lambdalisue added discussion enhancement New feature or request labels Feb 23, 2021
@nickjj
Copy link
Author

nickjj commented Feb 23, 2021

No. It's a bit incorrect. Fern creates a/ b/ rather than a/b/ for a/ b/ thus users get the result as-is.

Oh my machine (Ubuntu 20.04 LTS) with the latest version of Fern as of today if I run fern-action-new-path and type a/ b/ it will create this directory structure:

$ ls -laR

.:
total 80
drwxr-xr-x   3 nick nick  4096 Feb 23 13:44 .
drwxrwxrwt 210 root root 69632 Feb 23 13:45 ..
drwxr-xr-x   3 nick nick  4096 Feb 23 13:44 a

./a:
total 12
drwxr-xr-x 2 nick nick 4096 Feb 23 13:44 ' b'
drwxr-xr-x 3 nick nick 4096 Feb 23 13:44  .
drwxr-xr-x 3 nick nick 4096 Feb 23 13:44  ..

'./a/ b':
total 8
drwxr-xr-x 2 nick nick 4096 Feb 23 13:44 .
drwxr-xr-x 3 nick nick 4096 Feb 23 13:44 ..

And inside of Fern it creates a nested b/ inside of a/.

@lambdalisue
Copy link
Owner

lambdalisue commented Feb 23, 2021

I... don't really get what you mean. It seems the result you pasted is what exactly I expect.

I expect the following when you run fern-action-new-path with a/_b/ (assume _ is a whitespace)

  • a directory
  • _b directory in the above a directory (assume _ is a whitespace)

Is my expectation correct in your machine?

@nickjj
Copy link
Author

nickjj commented Feb 26, 2021

Yep that is what happens. I misread your initial reply because I missed the empty whitespace reference (good idea with using _).

@lambdalisue
Copy link
Owner

Ok, then fern worked as it designed.

Let's get back to the original. Do you (or anyone) have interface idea for creating multiple files/directories. Or are you satisfied with the current design while it create a file/directory as it designed?

@nickjj
Copy link
Author

nickjj commented Feb 27, 2021

It's a tricky one. It would be kind of neat if it worked like mkdir or touch where you can pass in a space separated list of paths, and if you happen to want a space in your path then you would quote it. This way you have the same interface to create 1 or many paths.

It could get complicated tho because then there's maybe doing things like touch a/b/{hello,world}, but I think this could be pretty easily avoided in Fern by invoking the create path action on the b directory in this case so the need for {} goes away.

@lambdalisue
Copy link
Owner

I'm sorry but I'm not going to apply breaking changes for this while most of people satisfied with the current interface.

@cairijun
Copy link

I find this feature could be handy for cpp devs. We regularly need to touch some_class.{h,cpp} but currently two fern-action-new-files are required. I made a quick and dirty workaround for this.

function! s:fern_exec(cmd) abort
    let node = fern#helper#new().sync.get_cursor_node()
    if l:node['status'] == g:fern#STATUS_NONE
        let node = l:node['__owner']
    endif
    let path = l:node['_path']
    let orig_path = getcwd()
    exec 'lcd ' . l:path
    execute '!' . a:cmd
    exec 'lcd ' . l:orig_path
endfunction
command! -complete=shellcmd -nargs=+ FernExec call s:fern_exec(<q-args>)
command! -complete=shellcmd -nargs=+ FernExecIn FernDo -stay :FernExec <args>

Usage: FernExecIn touch some_class.{h,cpp} should do what you expect.

@lambdalisue
Copy link
Owner

We regularly need to touch some_class.{h,cpp} but currently two fern-action-new-files are required.

Thanks, I didn't have that point 👍
Now I understand that the feature is convenient for some users. (it doesn't mean that I'm going to implement that feature thought.)

@lambdalisue
Copy link
Owner

lambdalisue commented Apr 15, 2021

Ah, well, I need to think about Windows... I'm sure that mkdir or touch doesn't work on Windows and I don't think it's good idea to parse the argument in fern to detect some_class.{h,cpp} or something like that while Vim script is horribly slow and it's not powerful enough to parse sh-like expressions.

@nickjj
Copy link
Author

nickjj commented Apr 15, 2021

I'm not sure how all Windows users use Vim but I am on Windows here and use terminal Vim within WSL which has access to all Unix commands. Is Fern coded today in such a way that it works with GUI Vim running in Windows?

@lambdalisue
Copy link
Owner

lambdalisue commented Apr 15, 2021

Is Fern coded today in such a way that it works with GUI Vim running in Windows?

I know some users are using fern on gVim in Windows.

I believe that supporting Windows is quite important feature of fern while tons of Vim plugins doesn't work well on Windows.
(I, personally, doesn't use Windows though.)

@cairijun
Copy link

Well, brace expansion in vim is not portable even in the Unix world. AFAIK it won't work on busybox. A portable solution might need a tedious vimscript implementation (which doesn't seem worth it), or some external dependency (which might be better to put in a seperated plugin):

@lambdalisue
Copy link
Owner

Well, brace expansion in vim is not portable even in the Unix world. AFAIK it won't work on busybox. A portable solution might need a tedious vimscript implementation (which doesn't seem worth it), or some external dependency (which might be better to put in a seperated plugin):

Well, I agree that perfect portability does not worth while I think nobody expect fern works on busybox or so on.
However, I think Windows is one of quite common environment thus I think it worth to support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants