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

copy file with m-c does not work when using bash cygwin as a shell in Windows #1033

Closed
9 of 15 tasks
jordi-frei opened this issue Sep 1, 2019 · 12 comments · Fixed by #1150
Closed
9 of 15 tasks

copy file with m-c does not work when using bash cygwin as a shell in Windows #1033

jordi-frei opened this issue Sep 1, 2019 · 12 comments · Fixed by #1150
Labels

Comments

@jordi-frei
Copy link

jordi-frei commented Sep 1, 2019

I use bash from cygwin as the shell in Gvim. When I try to copy a node NERDtree fails to do so. Resetting the shell to cmd.exe fixes the problem but I would prefer to use bash.

m-d and m-a to delete or create a new node works well

Thank you in advance

Self-Diagnosis

  • I have searched the issues for an answer to my question.
  • I have reviewed the NERDTree documentation. :h NERDTree
  • I have reviewed the Wiki.
  • I have searched the web for an answer to my question.

Environment (for bug reports)

  • Operating System: Windows 10

  • Vim/Neovim version :echo v:version:Gvim 8.0.586

  • NERDTree version, found on 1st line in NERDTree quickhelp ?: 5.3.1

  • vimrc settings

    settings for using cygwin bash as a shell

    " Makes bash open in the working directory
    let $CHERE_INVOKING=1
    " Default path for Cygwin 64-bit, change accordingly
    set shell=C:\cygwin64\bin\bash.exe
    " Without --login, Cygwin won't mount some directories such as /usr/bin/
    set shellcmdflag=--login\ -c
    " Default value is (, but bash needs "
    set shellxquote=\"
    " Paths will use / instead of \
    set shellslash
    

    other

    • NERDTree variables
    "
    map <C-n>  :NERDTreeToggle<CR>
    "  ignoring file types as in wildignore
    let NERDTreeRespectWildIgnore=1
    let NERDTreeNaturalSort=1
    autocmd StdinReadPre * let s:std_in=1
    "autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif
    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
    "  deleting old buffer when moving or replacing a file automathically
    let NERDTreeAutoDeleteBuffer=1
    let NERDTreeMinimalUI = 1
    let NERDTreeDirArrows = 1
    

    other

    • Other NERDTree-dependent Plugins
      • jistr/vim-nerdtree-tabs
      • ryanoasis/vim-devicons
      • tiagofumo/vim-nerdtree-syntax-highlight
      • Xuyuanp/nerdtree-git-plugin
      • Others (specify):
    • I've verified the issue occurs with only NERDTree installed.

Steps to Reproduce the Issue

  1. at the NERDtree panel press m-c to copy a node

Current Result (Include screenshots where appropriate.)

could not copy node

Expected Result

a new file should be created

@jordi-frei jordi-frei added the bug label Sep 1, 2019
@PhilRunninger
Copy link
Member

@jordi-frei cygwin is a tricky beast. It wants to behave like Linux with the bash utilities, but it's trapped inside of Windows. I suspect vim is treating this situation as if it's running on Windows. What does this command tell you? :echo nerdtree#runningWindows()

  • If you see 1, then NERDTree will use g:NERDTreeCopyDirCmd and g:NERDTreeCopyFileCmd to copy the node. By default, these variables are set to 'xcopy /s /e /i /y /q ' and 'copy /y ', respectively.
  • If you see 0, then NERDTree will use g:NERDTreeCopyCmd to copy the node. Its default is 'cp -r '.

All three of these variables can be set it your vimrc, but set only the one(s) you need. Try changing the appropriate variable(s), and see if that solves your issue.

@jordi-frei
Copy link
Author

@PhilRunninger thank you for your reply. I run :echo nerdtree#runningWindows() and I get 1. I saw that copying a directory works. Then I tried to modify NERDTreeCopyFileCmd to cp or to xcopy because I saw that copy command was not recognized in my shell but those two were working well.

none of these options work. what els can I try?

@PhilRunninger
Copy link
Member

Make sure the string has a space after the command, ie. let g:NERDTreeCopyFileCmd = 'cp '. Without the space, NERTree will send cpfoo bar to the OS.

@jordi-frei
Copy link
Author

still doesn't work, it keeps showing 'could not copy node'

:echo NERDTreeCopyFileCmd shows correctly cp

the rest of the m options work: a, m, d, p and l

@jordi-frei
Copy link
Author

jordi-frei commented Sep 3, 2019

I found a solution, but I don't know if it is a bug or not. I edited file fs_menu.vim and commented the following three lines from the function "NERDTreeCopyNode()":

"    let l:shellslash = &shellslash
"    let &shellslash = 0
"    let &shellslash = l:shellslash

I noticed that those lines were not present in the rest of similar functions. With this correction and the change in my vimrc as suggested by @PhilRunninger 👍
let g:NERDTreeCopyFileCmd = 'cp -r '

Now it works! is this a bug?

@jordi-frei
Copy link
Author

BTW, I had the same problem with removing directories and I wused the same workaround successfully.

@PhilRunninger
Copy link
Member

Yeah, it's probably a bug, in that only nerdtree#runningWindows() is checked. There is another function nerdtree#runningCygwin() that is relatively new, which could help out in this situation. If you issue the command :echo nerdtree#runningCygwin(), what does it return?

@jordi-frei
Copy link
Author

ok,

if I run it on gVim I get 0 (but I selected cygwin as the shell in gVim)
if I run vim from the cygwin terminal then I get 1 (but this is the cygwin vim version which is independent from gVim). I keep vim there for quick edits but don't use it very often

the m-c option from within cygwin terminal works just fine

It is a bit confusing but I hope I could explain.

@PhilRunninger
Copy link
Member

There was an issue earlier on that led me to add the lines you referenced above: #1033 (comment). Issue #776 was raised, and I think now that the fix (#952 and 842f5ca) may have been too hasty.

According to the Vim documentation, shellslash should be used when the chosen shell requires it. That would seem to support your use case and your suggestion that shellslash shouldn't be unset during the m-c and m-d operations.

I'd like @ZSaberLv0 to respond to this comment so that I can better understand the situation. Is shellslash used as a matter of necessity or of preference? I'm of the opinion that necessity should trump preference, and that if shellslash is used, then the shell should be compatible with that setting. Lines 974-980 of your zf_vimrc.vim seem to be in opposition to that premise, and are even acknowledged to be potentially troublesome.

@ZSaberLv0
Copy link

ZSaberLv0 commented Sep 16, 2019

I'd like @ZSaberLv0 to respond to this comment so that I can better understand the situation. Is shellslash used as a matter of necessity or of preference? I'm of the opinion that necessity should trump preference, and that if shellslash is used, then the shell should be compatible with that setting. Lines 974-980 of your zf_vimrc.vim seem to be in opposition to that premise, and are even acknowledged to be potentially troublesome.

@PhilRunninger For me, shell=cmd.exe is for necessity, and shellslash is for preference

Why shell=cmd.exe:

  • it works for both Cygwin and non-Cygwin envs
  • more convenient to run bat files
  • some Windows specified external command line tools use native encoding (GBK for example), it's hard to make it run for sh

Why shellslash:

  • when noshellslash, completing paths in source code may result to something like #include "path\file.h"
    • one main reason I use vim is, it can supply similar behavior under different platforms, with noshellslash, the behavior differs for Windows

I have shell=cmd.exe and shellslash settings for a long time, not aware of that it is not recommended, but it did make things more convenient

EDIT

since newer vim has completeslash, so I recommend everyone not to use shellslash anymore

@PhilRunninger
Copy link
Member

PhilRunninger commented Jul 11, 2020

@jordi-frei Are you still interested in a fix for this one? I have a pull request for you to try out: #1150

@ZSaberLv0 I wasn't notified of your edit; I just noticed it the other day. Can you verify this pull request is compatible with your completeslash setting?

Thanks to you both.

@ZSaberLv0
Copy link

@ZSaberLv0 I wasn't notified of your edit; I just noticed it the other day. Can you verify this pull request is compatible with your completeslash setting?

with completeslash and without shellslash, everything works fine

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants