vim-gtfo icon indicating copy to clipboard operation
vim-gtfo copied to clipboard

cannot cmd in current file whose directory starts with r

Open prabirshrestha opened this issue 8 years ago • 14 comments

If I have a file called d:\r\hello.txt and use got with let g:gtfo#terminals = { 'win' : 'cmd' } setting. The cmd opens and closes.

I'm suspecting it has do to something with \r being a special character.

This seems to open correctly.

!start cmd /k "cd /d "d:/r/hello.txt""

/k in cmd says to remain in the terminal so it does not exit after the script is complete. /d in cd says to change current drive. This would avoid parsing drive letter.

prabirshrestha avatar Jan 13 '17 05:01 prabirshrestha

gtfo.vim doesn't know the parameters for the numerous terminals in existence; they need to be provided explicitly. Try this instead:

let g:gtfo#terminals = { 'win' : 'cmd /k' }

justinmk avatar Jan 13 '17 13:01 justinmk

That seems to solve it. Would be good if it would be added to readme and doc.

prabirshrestha avatar Jan 13 '17 17:01 prabirshrestha

Worked in vim 8 on windows. But that doesn't seem to work on neovim on windows.

Here is what I get.

image

prabirshrestha avatar Jan 28 '17 23:01 prabirshrestha

Yep, there are some problems with shell escaping with Nvim on Windows. Please wait until 0.2. is released before using Nvim on Windows :)

justinmk avatar Jan 29 '17 00:01 justinmk

I saw that shell escaping PRs have been merged but when I got the latest master from neovim (https://github.com/neovim/neovim/commit/58d2ce9bdbb6feab7176f451ca0248c78606aa2e) I still see the same issue. I don't see any issues/PRs tagged with platform:windows. Are there still issues with shell escapes?

I do have set shellslash setting enabled.

prabirshrestha avatar Apr 15 '17 03:04 prabirshrestha

set shellslash with which 'shell' ?

I see that set shellslash works in gvim even if the shell is cmd.exe, but that's going to confuse some plugins. That's something that probably should be "fixed" in nvim, but not a high priority. It's counter to the intended purpose of 'shellslash'...

justinmk avatar Apr 15 '17 08:04 justinmk

Would be good if it would be added to readme and doc.

https://github.com/justinmk/vim-gtfo#settings does mention that, but I added a note to https://github.com/justinmk/vim-gtfo#platform-support also.

justinmk avatar Apr 15 '17 09:04 justinmk

@justinmk I use set shellslash with cmd to convert \ to / so c:\windows\system32 looks like c:/windows/system32. There are lot of plugin that handles this correctly. Even windows by default supports forward slashes.

image

prabirshrestha avatar Apr 16 '17 19:04 prabirshrestha

@prabirshrestha I thought you indicated that it's only a problem in neovim. Is it a gtfo.vim problem, present in vim and neovim? When I checked it did not seem to be a problem with gtfo.vim + gvim.

There are lot of plugin that handles this correctly.

Almost certainly by accident, e.g. they just happen to not send a path constructed by fnamemodify() to cmd.exe.

Even windows by default supports forward slashes.

Mostly, yes. Try it with del and other commands. Hence why Nvim has to continue the silly dance.

justinmk avatar Apr 17 '17 00:04 justinmk

In gvim/vim it works correctly on windows with set shellslash. The problem is only with neovim so I would consider it a bug. Let me know if you would like me to file a bug on neovim to track this.

del a/b.txt doesn't work because some of windows commands uses / as separator.

prabirshrestha avatar Apr 25 '17 21:04 prabirshrestha

@prabirshrestha If you can come up with a minimal test case a bug report at neovim repo would be most welcome.

justinmk avatar Apr 25 '17 21:04 justinmk

@justinmk Here is the minimal vimrc.

" clone in ~/.vimplugins/vim-gtfo
" git clone https://github.com/justinmk/vim-gtfo .vimplugins/vim-gtfo
set nocompatible
syntax on
filetype plugin indent on

if has('win32') || has('win64')
    set shellslash
endif

set runtimepath+=~/.vimplugins/vim-gtfo

if has('win32') || has('win64')
  let g:gtfo#terminals = { 'win' : 'cmd /k' }
endif

Vim8:

gvim -- -u minimal-vimrc.vim
:e ~/.vimrc
gof
got

gof and got works in Vim8. Now try the same in neovim-qt on windows and it fails nvim-qt -- -u minimal-vimrc.vim. It errors with - The syntax of the command is incorrect. and doesn't open terminal nor the windows explorer. If I remove set shellslash it works in neovim.

prabirshrestha avatar Jun 01 '17 20:06 prabirshrestha

@justinmk Still doesn't seem to work with latest neovim 2.2/2.3

prabirshrestha avatar Dec 18 '17 06:12 prabirshrestha

@justinmk I think I finally figured out the problem.

This code doesn't work. set shell=$COMSPEC

func! s:force_cmdexe() abort
  if &shell !~? "cmd" || &shellslash
    let s:shell=&shell | let s:shslash=&shellslash | let s:shcmdflag=&shellcmdflag
    set shell=$COMSPEC noshellslash shellcmdflag=/c
  endif
endf

Changing it to the following code seems to work. exec 'set shell='.$COMSPEC.

func! s:force_cmdexe() abort
  if &shell !~? "cmd" || &shellslash
    let s:shell=&shell | let s:shslash=&shellslash | let s:shcmdflag=&shellcmdflag
    exec 'set shell='.$COMSPEC
    set noshellslash shellcmdflag=/c
  endif
endf

Would be possible to update the plugin to use this code in the meantime while we have a proper fix for neovim?

prabirshrestha avatar Jan 10 '18 06:01 prabirshrestha