To: vim_dev@googlegroups.com Subject: Patch 8.0.1455 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1455 Problem: If $SHELL contains a space then the default value of 'shell' is incorrect. (Matthew Horan) Solution: Escape spaces in $SHELL. (Christian Brabandt, closes #459) Files: src/option.c, runtime/doc/options.txt, src/testdir/test_startup.vim *** ../vim-8.0.1454/src/option.c 2018-01-31 21:48:25.228668790 +0100 --- src/option.c 2018-02-03 14:55:26.090530676 +0100 *************** *** 3265,3270 **** --- 3265,3271 ---- static void set_option_default(int, int opt_flags, int compatible); static void set_options_default(int opt_flags); + static void set_string_default_esc(char *name, char_u *val, int escape); static char_u *term_bg_default(void); static void did_set_option(int opt_idx, int opt_flags, int new_value); static char_u *illegal_char(char_u *, int); *************** *** 3371,3377 **** # endif #endif ) ! set_string_default("sh", p); #ifdef FEAT_WILDIGN /* --- 3372,3378 ---- # endif #endif ) ! set_string_default_esc("sh", p, TRUE); #ifdef FEAT_WILDIGN /* *************** *** 3859,3872 **** /* * Set the Vi-default value of a string option. * Used for 'sh', 'backupskip' and 'term'. */ ! void ! set_string_default(char *name, char_u *val) { char_u *p; int opt_idx; ! p = vim_strsave(val); if (p != NULL) /* we don't want a NULL */ { opt_idx = findoption((char_u *)name); --- 3860,3877 ---- /* * Set the Vi-default value of a string option. * Used for 'sh', 'backupskip' and 'term'. + * When "escape" is TRUE escape spaces with a backslash. */ ! static void ! set_string_default_esc(char *name, char_u *val, int escape) { char_u *p; int opt_idx; ! if (escape && vim_strchr(val, ' ') != NULL) ! p = vim_strsave_escaped(val, (char_u *)" "); ! else ! p = vim_strsave(val); if (p != NULL) /* we don't want a NULL */ { opt_idx = findoption((char_u *)name); *************** *** 3880,3885 **** --- 3885,3896 ---- } } + void + set_string_default(char *name, char_u *val) + { + set_string_default_esc(name, val, FALSE); + } + /* * Set the Vi-default value of a number option. * Used for 'lines' and 'columns'. *** ../vim-8.0.1454/runtime/doc/options.txt 2018-01-31 21:48:25.220668839 +0100 --- runtime/doc/options.txt 2018-02-03 15:03:05.959374586 +0100 *************** *** 6523,6539 **** It is allowed to give an argument to the command, e.g. "csh -f". See |option-backslash| about including spaces and backslashes. Environment variables are expanded |:set_env|. If the name of the shell contains a space, you might need to enclose ! it in quotes. Example: > :set shell=\"c:\program\ files\unix\sh.exe\"\ -f < Note the backslash before each quote (to avoid starting a comment) and each space (to avoid ending the option value). Also note that the "-f" is not inside the quotes, because it is not part of the command ! name. And Vim automagically recognizes the backslashes that are path separators. ! For Dos 32 bits (DJGPP), you can set the $DJSYSFLAGS environment ! variable to change the way external commands are executed. See the ! libc.inf file of DJGPP. Under MS-Windows, when the executable ends in ".com" it must be included. Thus setting the shell to "command.com" or "4dos.com" works, but "command" and "4dos" do not work for all commands (e.g., --- 6630,6650 ---- It is allowed to give an argument to the command, e.g. "csh -f". See |option-backslash| about including spaces and backslashes. Environment variables are expanded |:set_env|. + If the name of the shell contains a space, you might need to enclose ! it in quotes or escape the space. Example with quotes: > :set shell=\"c:\program\ files\unix\sh.exe\"\ -f < Note the backslash before each quote (to avoid starting a comment) and each space (to avoid ending the option value). Also note that the "-f" is not inside the quotes, because it is not part of the command ! name. Vim automagically recognizes the backslashes that are path separators. ! Example with escaped space (Vim will do this when initializing the ! option from $SHELL): > ! :set shell=/bin/with\\\ space/sh ! < The resulting value of 'shell' is "/bin/with\ space/sh", two ! backslashes are consumed by `:set`. ! Under MS-Windows, when the executable ends in ".com" it must be included. Thus setting the shell to "command.com" or "4dos.com" works, but "command" and "4dos" do not work for all commands (e.g., *************** *** 6553,6560 **** Flag passed to the shell to execute "!" and ":!" commands; e.g., "bash.exe -c ls" or "command.com /c dir". For the MS-DOS-like systems, the default is set according to the value of 'shell', to ! reduce the need to set this option by the user. It's not used for ! OS/2 (EMX figures this out itself). On Unix it can have more than one flag. Each white space separated part is passed as an argument to the shell command. See |option-backslash| about including spaces and backslashes. --- 6664,6670 ---- Flag passed to the shell to execute "!" and ":!" commands; e.g., "bash.exe -c ls" or "command.com /c dir". For the MS-DOS-like systems, the default is set according to the value of 'shell', to ! reduce the need to set this option by the user. On Unix it can have more than one flag. Each white space separated part is passed as an argument to the shell command. See |option-backslash| about including spaces and backslashes. *** ../vim-8.0.1454/src/testdir/test_startup.vim 2017-09-26 17:40:40.591681236 +0200 --- src/testdir/test_startup.vim 2018-02-03 15:11:32.279872168 +0100 *************** *** 226,231 **** --- 226,245 ---- call delete('Xtestout') endfunc + func Test_set_shell() + let after = [ + \ 'call writefile([&shell], "Xtestout")', + \ 'quit!', + \ ] + let $SHELL = '/bin/with space/sh' + if RunVimPiped([], after, '', '') + let lines = readfile('Xtestout') + " MS-Windows adds a space after the word + call assert_equal('/bin/with\ space/sh', lines[0]) + endif + call delete('Xtestout') + endfunc + func Test_progpath() " Tests normally run with "./vim" or "../vim", these must have been expanded " to a full path. *** ../vim-8.0.1454/src/version.c 2018-02-03 14:46:41.398054549 +0100 --- src/version.c 2018-02-03 15:11:58.575689874 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1455, /**/ -- "Intelligence has much less practical application than you'd think." -- Scott Adams, Dilbert. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///