Karsten Hopp a63318
To: vim_dev@googlegroups.com
Karsten Hopp a63318
Subject: Patch 7.3.443
Karsten Hopp a63318
Fcc: outbox
Karsten Hopp a63318
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp a63318
Mime-Version: 1.0
Karsten Hopp a63318
Content-Type: text/plain; charset=UTF-8
Karsten Hopp a63318
Content-Transfer-Encoding: 8bit
Karsten Hopp a63318
------------
Karsten Hopp a63318
Karsten Hopp a63318
Patch 7.3.443
Karsten Hopp a63318
Problem:    MS-Windows: 'shcf' and 'shellxquote' defaults are not very good.
Karsten Hopp a63318
Solution:   Make a better guess when 'shell' is set to "cmd.exe". (Ben Fritz)
Karsten Hopp a63318
Files:      src/option.c, runtime/doc/options.txt
Karsten Hopp a63318
Karsten Hopp a63318
Karsten Hopp a63318
*** ../vim-7.3.442/src/option.c	2012-01-28 18:03:30.000000000 +0100
Karsten Hopp a63318
--- src/option.c	2012-02-12 23:17:55.000000000 +0100
Karsten Hopp a63318
***************
Karsten Hopp a63318
*** 3883,3889 ****
Karsten Hopp a63318
  
Karsten Hopp a63318
  #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
Karsten Hopp a63318
      /*
Karsten Hopp a63318
!      * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
Karsten Hopp a63318
       * This is done after other initializations, where 'shell' might have been
Karsten Hopp a63318
       * set, but only if they have not been set before.  Default for p_shcf is
Karsten Hopp a63318
       * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
Karsten Hopp a63318
--- 3883,3890 ----
Karsten Hopp a63318
  
Karsten Hopp a63318
  #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
Karsten Hopp a63318
      /*
Karsten Hopp a63318
!      * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
Karsten Hopp a63318
!      * 'shell' option.
Karsten Hopp a63318
       * This is done after other initializations, where 'shell' might have been
Karsten Hopp a63318
       * set, but only if they have not been set before.  Default for p_shcf is
Karsten Hopp a63318
       * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
Karsten Hopp a63318
***************
Karsten Hopp a63318
*** 3920,3925 ****
Karsten Hopp a63318
--- 3921,3962 ----
Karsten Hopp a63318
  #  endif
Karsten Hopp a63318
  # endif
Karsten Hopp a63318
      }
Karsten Hopp a63318
+     else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
Karsten Hopp a63318
+     {
Karsten Hopp a63318
+ 	int	idx3;
Karsten Hopp a63318
+ 
Karsten Hopp a63318
+ 	/*
Karsten Hopp a63318
+ 	 * cmd.exe on Windows will strip the first and last double quote given
Karsten Hopp a63318
+ 	 * on the command line, e.g. most of the time things like:
Karsten Hopp a63318
+ 	 *   cmd /c "my path/to/echo" "my args to echo"
Karsten Hopp a63318
+ 	 * become:
Karsten Hopp a63318
+ 	 *   my path/to/echo" "my args to echo
Karsten Hopp a63318
+ 	 * when executed.
Karsten Hopp a63318
+ 	 *
Karsten Hopp a63318
+ 	 * To avoid this, use the /s argument in addition to /c to force the
Karsten Hopp a63318
+ 	 * stripping behavior, and also set shellxquote to automatically
Karsten Hopp a63318
+ 	 * surround the entire command in quotes (which get stripped as
Karsten Hopp a63318
+ 	 * noted).
Karsten Hopp a63318
+ 	 */
Karsten Hopp a63318
+ 
Karsten Hopp a63318
+ 	/* Set shellxquote default to add the quotes to be stripped. */
Karsten Hopp a63318
+ 	idx3 = findoption((char_u *)"sxq");
Karsten Hopp a63318
+ 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Karsten Hopp a63318
+ 	{
Karsten Hopp a63318
+ 	    p_sxq = (char_u *)"\"";
Karsten Hopp a63318
+ 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
Karsten Hopp a63318
+ 	}
Karsten Hopp a63318
+ 
Karsten Hopp a63318
+ 	/* Set shellcmdflag default to always strip the quotes, note the order
Karsten Hopp a63318
+ 	 * between /s and /c is important or cmd.exe will treat the /s as part
Karsten Hopp a63318
+ 	 * of the command to be executed.  */
Karsten Hopp a63318
+ 	idx3 = findoption((char_u *)"shcf");
Karsten Hopp a63318
+ 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Karsten Hopp a63318
+ 	{
Karsten Hopp a63318
+ 	    p_shcf = (char_u *)"/s /c";
Karsten Hopp a63318
+ 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
Karsten Hopp a63318
+ 	}
Karsten Hopp a63318
+     }
Karsten Hopp a63318
  #endif
Karsten Hopp a63318
  
Karsten Hopp a63318
  #ifdef FEAT_TITLE
Karsten Hopp a63318
*** ../vim-7.3.442/runtime/doc/options.txt	2011-06-26 05:36:07.000000000 +0200
Karsten Hopp a63318
--- runtime/doc/options.txt	2012-02-12 23:21:59.000000000 +0100
Karsten Hopp a63318
***************
Karsten Hopp a63318
*** 5880,5895 ****
Karsten Hopp a63318
  	security reasons.
Karsten Hopp a63318
  
Karsten Hopp a63318
  						*'shellcmdflag'* *'shcf'*
Karsten Hopp a63318
! 'shellcmdflag' 'shcf'	string	(default: "-c", MS-DOS and Win32, when 'shell'
Karsten Hopp a63318
! 					does not contain "sh" somewhere: "/c")
Karsten Hopp a63318
  			global
Karsten Hopp a63318
  			{not in Vi}
Karsten Hopp a63318
  	Flag passed to the shell to execute "!" and ":!" commands; e.g.,
Karsten Hopp a63318
  	"bash.exe -c ls" or "command.com /c dir".  For the MS-DOS-like
Karsten Hopp a63318
  	systems, the default is set according to the value of 'shell', to
Karsten Hopp a63318
  	reduce the need to set this option by the user.  It's not used for
Karsten Hopp a63318
! 	OS/2 (EMX figures this out itself).  See |option-backslash| about
Karsten Hopp a63318
! 	including spaces and backslashes.  See |dos-shell|.
Karsten Hopp a63318
  	This option cannot be set from a |modeline| or in the |sandbox|, for
Karsten Hopp a63318
  	security reasons.
Karsten Hopp a63318
  
Karsten Hopp a63318
--- 5899,5919 ----
Karsten Hopp a63318
  	security reasons.
Karsten Hopp a63318
  
Karsten Hopp a63318
  						*'shellcmdflag'* *'shcf'*
Karsten Hopp a63318
! 'shellcmdflag' 'shcf'	string	(default: "-c";
Karsten Hopp a63318
! 				 Win32, when 'shell' is cmd.exe: "/s /c";
Karsten Hopp a63318
! 				 MS-DOS and Win32, when 'shell' neither is
Karsten Hopp a63318
! 				 cmd.exe nor contains "sh" somewhere: "/c")
Karsten Hopp a63318
  			global
Karsten Hopp a63318
  			{not in Vi}
Karsten Hopp a63318
  	Flag passed to the shell to execute "!" and ":!" commands; e.g.,
Karsten Hopp a63318
  	"bash.exe -c ls" or "command.com /c dir".  For the MS-DOS-like
Karsten Hopp a63318
  	systems, the default is set according to the value of 'shell', to
Karsten Hopp a63318
  	reduce the need to set this option by the user.  It's not used for
Karsten Hopp a63318
! 	OS/2 (EMX figures this out itself).
Karsten Hopp a63318
! 	On Unix it can have more than one flag.  Each white space separated
Karsten Hopp a63318
! 	part is passed as an argument to the shell command.
Karsten Hopp a63318
! 	See |option-backslash| about including spaces and backslashes.
Karsten Hopp a63318
! 	Also see |dos-shell| for MS-DOS and MS-Windows.
Karsten Hopp a63318
  	This option cannot be set from a |modeline| or in the |sandbox|, for
Karsten Hopp a63318
  	security reasons.
Karsten Hopp a63318
  
Karsten Hopp a63318
***************
Karsten Hopp a63318
*** 5910,5918 ****
Karsten Hopp a63318
  	For Unix the default it "| tee".  The stdout of the compiler is saved
Karsten Hopp a63318
  	in a file and echoed to the screen.  If the 'shell' option is "csh" or
Karsten Hopp a63318
  	"tcsh" after initializations, the default becomes "|& tee".  If the
Karsten Hopp a63318
! 	'shell' option is "sh", "ksh", "zsh" or "bash" the default becomes
Karsten Hopp a63318
! 	"2>&1| tee".  This means that stderr is also included.  Before using
Karsten Hopp a63318
! 	the 'shell' option a path is removed, thus "/bin/sh" uses "sh".
Karsten Hopp a63318
  	The initialization of this option is done after reading the ".vimrc"
Karsten Hopp a63318
  	and the other initializations, so that when the 'shell' option is set
Karsten Hopp a63318
  	there, the 'shellpipe' option changes automatically, unless it was
Karsten Hopp a63318
--- 5934,5943 ----
Karsten Hopp a63318
  	For Unix the default it "| tee".  The stdout of the compiler is saved
Karsten Hopp a63318
  	in a file and echoed to the screen.  If the 'shell' option is "csh" or
Karsten Hopp a63318
  	"tcsh" after initializations, the default becomes "|& tee".  If the
Karsten Hopp a63318
! 	'shell' option is "sh", "ksh", "mksh", "pdksh", "zsh" or "bash" the
Karsten Hopp a63318
! 	default becomes "2>&1| tee".  This means that stderr is also included.
Karsten Hopp a63318
! 	Before using the 'shell' option a path is removed, thus "/bin/sh" uses
Karsten Hopp a63318
! 	"sh".
Karsten Hopp a63318
  	The initialization of this option is done after reading the ".vimrc"
Karsten Hopp a63318
  	and the other initializations, so that when the 'shell' option is set
Karsten Hopp a63318
  	there, the 'shellpipe' option changes automatically, unless it was
Karsten Hopp a63318
***************
Karsten Hopp a63318
*** 6017,6024 ****
Karsten Hopp a63318
  
Karsten Hopp a63318
  						*'shellxquote'* *'sxq'*
Karsten Hopp a63318
  'shellxquote' 'sxq'	string	(default: "";
Karsten Hopp a63318
! 					for Win32, when 'shell' contains "sh"
Karsten Hopp a63318
! 					somewhere: "\""
Karsten Hopp a63318
  					for Unix, when using system(): "\"")
Karsten Hopp a63318
  			global
Karsten Hopp a63318
  			{not in Vi}
Karsten Hopp a63318
--- 6043,6050 ----
Karsten Hopp a63318
  
Karsten Hopp a63318
  						*'shellxquote'* *'sxq'*
Karsten Hopp a63318
  'shellxquote' 'sxq'	string	(default: "";
Karsten Hopp a63318
! 					for Win32, when 'shell' is cmd.exe or
Karsten Hopp a63318
! 					contains "sh" somewhere: "\""
Karsten Hopp a63318
  					for Unix, when using system(): "\"")
Karsten Hopp a63318
  			global
Karsten Hopp a63318
  			{not in Vi}
Karsten Hopp a63318
***************
Karsten Hopp a63318
*** 6026,6036 ****
Karsten Hopp a63318
  	the "!" and ":!" commands.  Includes the redirection.  See
Karsten Hopp a63318
  	'shellquote' to exclude the redirection.  It's probably not useful
Karsten Hopp a63318
  	to set both options.
Karsten Hopp a63318
! 	This is an empty string by default.  Known to be useful for
Karsten Hopp a63318
! 	third-party shells when using the Win32 version, such as the MKS Korn
Karsten Hopp a63318
! 	Shell or bash, where it should be "\"".  The default is adjusted
Karsten Hopp a63318
! 	according the value of 'shell', to reduce the need to set this option
Karsten Hopp a63318
! 	by the user.  See |dos-shell|.
Karsten Hopp a63318
  	This option cannot be set from a |modeline| or in the |sandbox|, for
Karsten Hopp a63318
  	security reasons.
Karsten Hopp a63318
  
Karsten Hopp a63318
--- 6052,6063 ----
Karsten Hopp a63318
  	the "!" and ":!" commands.  Includes the redirection.  See
Karsten Hopp a63318
  	'shellquote' to exclude the redirection.  It's probably not useful
Karsten Hopp a63318
  	to set both options.
Karsten Hopp a63318
! 	This is an empty string by default on most systems, but is known to be
Karsten Hopp a63318
! 	useful for on Win32 version, either for cmd.exe which automatically
Karsten Hopp a63318
! 	strips off the first and last quote on a command, or 3rd-party shells
Karsten Hopp a63318
! 	such as the MKS Korn Shell or bash, where it should be "\"".  The
Karsten Hopp a63318
! 	default is adjusted according the value of 'shell', to reduce the need
Karsten Hopp a63318
! 	to set this option by the user.  See |dos-shell|.
Karsten Hopp a63318
  	This option cannot be set from a |modeline| or in the |sandbox|, for
Karsten Hopp a63318
  	security reasons.
Karsten Hopp a63318
  
Karsten Hopp a63318
*** ../vim-7.3.442/src/version.c	2012-02-12 20:13:55.000000000 +0100
Karsten Hopp a63318
--- src/version.c	2012-02-12 23:18:40.000000000 +0100
Karsten Hopp a63318
***************
Karsten Hopp a63318
*** 716,717 ****
Karsten Hopp a63318
--- 716,719 ----
Karsten Hopp a63318
  {   /* Add new patch number below this line */
Karsten Hopp a63318
+ /**/
Karsten Hopp a63318
+     443,
Karsten Hopp a63318
  /**/
Karsten Hopp a63318
Karsten Hopp a63318
-- 
Karsten Hopp a63318
CVS sux, men don't like commitment
Karsten Hopp a63318
Karsten Hopp a63318
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp a63318
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp a63318
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp a63318
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///