diff options
author | Mike Williams <mikew@globalgraphics.com> | 2021-06-28 20:53:58 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-28 20:53:58 +0200 |
commit | 127950241e84c822d3c50f46a00d42a70d2d5cb6 (patch) | |
tree | 6b5a0ac43a29edeb6e1cc3c3fb9f7c6f966cb28e /src/option.c | |
parent | ffec6dd16a766180429addaa78928c773a3c9832 (diff) |
patch 8.2.3071: shell options are not set properly for PowerShellv8.2.3071
Problem: Shell options are not set properly for PowerShell.
Solution: Use better option defaults. (Mike Willams, closes #8459)
Diffstat (limited to 'src/option.c')
-rw-r--r-- | src/option.c | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/option.c b/src/option.c index 07bb71e4d6..5fc059e29d 100644 --- a/src/option.c +++ b/src/option.c @@ -932,6 +932,27 @@ set_init_3(void) options[idx_srr].def_val[VI_DEFAULT] = p_srr; } } +# ifdef MSWIN + // PowerShell 5.1/.NET outputs UTF-16 with BOM so re-encode to the + // current codepage + else if ( fnamecmp(p, "powershell") == 0 + || fnamecmp(p, "powershell.exe") == 0 + ) + { +# if defined(FEAT_QUICKFIX) + if (do_sp) + { + p_sp = (char_u *)"2>&1 | Out-File -Encoding default"; + options[idx_sp].def_val[VI_DEFAULT] = p_sp; + } +# endif + if (do_srr) + { + p_srr = (char_u *)"2>&1 | Out-File -Encoding default"; + options[idx_srr].def_val[VI_DEFAULT] = p_srr; + } + } +#endif else // Always use POSIX shell style redirection if we reach this if ( fnamecmp(p, "sh") == 0 @@ -984,11 +1005,35 @@ set_init_3(void) * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the * 'shell' option. * This is done after other initializations, where 'shell' might have been - * set, but only if they have not been set before. Default for p_shcf is - * "/c", for p_shq is "". For "sh" like shells it is changed here to - * "-c" and "\"". And for Win32 we need to set p_sxq instead. + * set, but only if they have not been set before. + * Default values depend on shell (cmd.exe is default shell): + * + * p_shcf p_sxq + * cmd.exe - "/c" "(" + * powershell.exe - "-Command" "\"" + * "sh" like shells - "-c" "\"" + * + * For Win32 p_sxq is set instead of p_shq to include shell redirection. */ - if (strstr((char *)gettail(p_sh), "sh") != NULL) + if (strstr((char *)gettail(p_sh), "powershell") != NULL) + { + int idx_opt; + + idx_opt = findoption((char_u *)"shcf"); + if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) + { + p_shcf = (char_u*)"-Command"; + options[idx_opt].def_val[VI_DEFAULT] = p_shcf; + } + + idx_opt = findoption((char_u *)"sxq"); + if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) + { + p_sxq = (char_u*)"\""; + options[idx_opt].def_val[VI_DEFAULT] = p_sxq; + } + } + else if (strstr((char *)gettail(p_sh), "sh") != NULL) { int idx3; |