# HG changeset patch # User Christian Brabandt # Date 1517667305 -3600 # Node ID 51521b8a370cbf6fd4a124c107156b73a509be99 # Parent 12a782ea6e51885139617e9a9c87531fefcd1df6 patch 8.0.1455: if $SHELL contains a space then 'shell' is incorrect commit https://github.com/vim/vim/commit/4bfa8af14142e54f509048239f4e8596911f56aa Author: Bram Moolenaar Date: Sat Feb 3 15:14:46 2018 +0100 patch 8.0.1455: if $SHELL contains a space then 'shell' is incorrect 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) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -6630,14 +6630,21 @@ A jump table for the options with a shor 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: > + 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. And Vim automagically recognizes the backslashes that are path + 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., diff --git a/src/option.c b/src/option.c --- a/src/option.c +++ b/src/option.c @@ -3265,6 +3265,7 @@ static char *(p_scl_values[]) = {"yes", 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,7 +3372,7 @@ set_init_1(void) # endif #endif ) - set_string_default("sh", p); + set_string_default_esc("sh", p, TRUE); #ifdef FEAT_WILDIGN /* @@ -3859,14 +3860,18 @@ set_options_default( /* * Set the Vi-default value of a string option. * Used for 'sh', 'backupskip' and 'term'. - */ - void -set_string_default(char *name, char_u *val) + * 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; - p = vim_strsave(val); + 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,6 +3885,12 @@ set_string_default(char *name, char_u *v } } + 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'. diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim --- a/src/testdir/test_startup.vim +++ b/src/testdir/test_startup.vim @@ -226,6 +226,20 @@ func Test_read_stdin() 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. diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -772,6 +772,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1455, +/**/ 1454, /**/ 1453,