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

Use shellescape() instead of fnameescape() to escape file names #15

Closed
fritzophrenic opened this issue Mar 26, 2013 · 4 comments
Closed

Comments

@fritzophrenic
Copy link

I had to change fnameescape() to shellescape() to avoid errors when editing files in a path containing spaces in Windows 7.

Something like this needs to be done for all supported VCS types:

let sh_sav = &shellslash
if has('win32')
  set noshellslash
endif
let diff = system('hg diff --nodates -U0 -- '. shellescape(a:path) .' | findstr "^@@ "')
let &shellslash = sh_sav

fnameescape() is meant for arguments to Vim functions or commands, and shellescape() is meant for arguments to external commands. The system() call is the latter.

@mhinz mhinz closed this as completed in 5383932 Mar 26, 2013
@mhinz
Copy link
Owner

mhinz commented Mar 26, 2013

Hmm, I knew of the difference but somehow assumend that, because Vim's system() is just a wrapper to system-specific functions, it would be fine.

(Yes, ':h system' stresses that..)

Thanks!

@mhinz mhinz reopened this Mar 27, 2013
@mhinz
Copy link
Owner

mhinz commented Mar 27, 2013

Do I have to set noshellslash for every casewhen I use shellescape() on win32?

@fritzophrenic
Copy link
Author

Do I have to set noshellslash for every casewhen I use shellescape() on win32?

:help 'shellslash' says:

This is
useful when a Unix-like shell is used instead of command.com or
cmd.exe.  Backward slashes can still be typed, but they are changed to
forward slashes by Vim.

But many people use it even with cmd.exe because it lets you use forward slashes within Vim easier, and most (but not all) Windows programs in cmd.exe will work with both forward and backwards slashes.

It would probably be best, if you also test the value of 'shell' to see whether it actually is still set to start with "command" or "cmd"; shellslash can remain set if a Unix-like shell is actually being used. The reason for resetting 'shellslash' if cmd.exe or similar is in use, is that shellescape() assumes a Unix-like shell if shellslash is set.

@fritzophrenic
Copy link
Author

I added a note to 1de08cb, I got it working with a minor modification. Thanks for fixing this!

@mhinz mhinz closed this as completed in 884faa1 Mar 27, 2013
CrazedProgrammer added a commit to CrazedProgrammer/nix that referenced this issue Sep 22, 2021
In addition, some fnameescape()s used in shell command arguments
were changed to shellescape()s, which is more correct.
Source: mhinz/vim-signify#15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants