[vim/vim] Input redirection doesn't work with powershell (PR #11257)

17 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Oct 1, 2022, 1:53:11 PM10/1/22
to vim/vim, Subscribed

Patch contributed by Enan Ajmain.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/11257

Commit Summary

  • a7a5653 Input redirection doesn't work with powershell
  • c379d15 Merge branch 'vim:master' into cmdexpand

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257@github.com>

codecov[bot]

unread,
Oct 1, 2022, 2:05:04 PM10/1/22
to vim/vim, Subscribed

Codecov Report

Merging #11257 (6b39125) into master (b850c39) will increase coverage by 0.61%.
The diff coverage is 81.81%.

@@            Coverage Diff             @@

##           master   #11257      +/-   ##

==========================================

+ Coverage   81.82%   82.44%   +0.61%     

==========================================

  Files         162      152      -10     

  Lines      188943   178951    -9992     

  Branches    42960    40612    -2348     

==========================================

- Hits       154607   147537    -7070     

+ Misses      21790    19150    -2640     

+ Partials    12546    12264     -282     
Flag Coverage Δ
huge-clang-none 82.72% <81.81%> (-0.01%) ⬇️
huge-gcc-none ?
huge-gcc-testgui 53.10% <0.00%> (+<0.01%) ⬆️
huge-gcc-unittests 0.29% <0.00%> (-0.01%) ⬇️
linux 82.44% <81.81%> (-0.06%) ⬇️
mingw-x64-HUGE ?
mingw-x86-HUGE ?
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/ex_cmds.c 86.13% <81.81%> (+0.45%) ⬆️
src/regexp_bt.c 78.48% <0.00%> (-7.48%) ⬇️
src/json.c 77.84% <0.00%> (-5.47%) ⬇️
src/regexp_nfa.c 84.89% <0.00%> (-4.65%) ⬇️
src/libvterm/src/parser.c 55.18% <0.00%> (-4.15%) ⬇️
src/edit.c 82.86% <0.00%> (-3.49%) ⬇️
src/gui.c 69.78% <0.00%> (-3.20%) ⬇️
src/normal.c 87.93% <0.00%> (-3.00%) ⬇️
src/clipboard.c 71.68% <0.00%> (-2.91%) ⬇️
src/libvterm/src/screen.c 50.18% <0.00%> (-2.85%) ⬇️
... and 122 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/c1264439868@github.com>

Yegappan Lakshmanan

unread,
Oct 1, 2022, 7:06:28 PM10/1/22
to vim/vim, Push

@yegappan pushed 1 commit.

  • 8de2356 Input redirection doesn't work with powershell


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11197378098@github.com>

Yegappan Lakshmanan

unread,
Oct 2, 2022, 10:57:40 AM10/2/22
to vim/vim, Push

@yegappan pushed 1 commit.

  • ea4e58d Input redirection doesn't work with powershell

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11200677708@github.com>

Yegappan Lakshmanan

unread,
Oct 2, 2022, 12:26:53 PM10/2/22
to vim/vim, Push

@yegappan pushed 3 commits.

    • a7a5653 Input redirection doesn't work with powershell

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11201067974@github.com>

    Enan Ajmain

    unread,
    Oct 2, 2022, 1:04:28 PM10/2/22
    to vim/vim, Subscribed

    @3N4N commented on this pull request.


    In src/ex_cmds.c:

    > +	if (is_powershell)
    +	    len = (long_u)STRLEN(cmd) + 3;
    +	else
    +	    len = (long_u)STRLEN(cmd) + 3;			// "()" + NUL
    

    Check for powershell looks redundant.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127670402@github.com>

    Enan Ajmain

    unread,
    Oct 2, 2022, 1:06:22 PM10/2/22
    to vim/vim, Subscribed

    @3N4N commented on this pull request.


    In src/ex_cmds.c:

    >      if (is_fish_shell)
     	len = (long_u)STRLEN(cmd) + 13;		// "begin; " + "; end" + NUL
         else
     #endif
    -	len = (long_u)STRLEN(cmd) + 3;			// "()" + NUL
    +    {
    +	is_powershell = (shell_name[0] == 'p')
    

    PowerShell is nowadays available for Linux, too, in the form of PowerShell Core (v7). (Ignore if we don't care about that too much; who would use powershell in Linux anyway?)


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127670590@github.com>

    Enan Ajmain

    unread,
    Oct 2, 2022, 1:08:47 PM10/2/22
    to vim/vim, Subscribed

    @3N4N commented on this pull request.


    In src/ex_cmds.c:

    > +	    // "& { Get-Content" + " | & " + " }"
    +	    len += (long_u)STRLEN(itmp) + 23;
    

    There is a space after Get-Content (see L1603). len should be 24, I think.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127670864@github.com>

    Enan Ajmain

    unread,
    Oct 2, 2022, 1:10:28 PM10/2/22
    to vim/vim, Subscribed

    @3N4N commented on this pull request.


    In src/ex_cmds.c:

    >      if (is_fish_shell)
     	len = (long_u)STRLEN(cmd) + 13;		// "begin; " + "; end" + NUL
         else
     #endif
    -	len = (long_u)STRLEN(cmd) + 3;			// "()" + NUL
    +    {
    +	is_powershell = (shell_name[0] == 'p')
    

    Never mind. I misread #endif as #else.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127671027@github.com>

    Enan Ajmain

    unread,
    Oct 2, 2022, 1:18:59 PM10/2/22
    to vim/vim, Subscribed

    @3N4N commented on this pull request.


    In src/ex_cmds.c:

    >  #else
    -    // For shells that don't understand braces around commands, at least allow
    -    // the use of commands in a pipe.
    -    if (*p_sxe != NUL && *p_sxq == '(')
    +    if (is_powershell)
    

    Okay, here is where I wanted to mention powershell being available for Linux, too (mistakenly did so on a previous line). Taking the if is_powershell block above #ifdef UNIX should be enough. (Unless we don't care for people using PowerShell on Linux, assuming anyone does.)


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127671848@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 12:27:21 AM10/3/22
    to vim/vim, Push

    @yegappan pushed 1 commit.

    • f85c960 Support powershell in Unix-like systems

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11204172968@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 12:27:50 AM10/3/22
    to vim/vim, Push

    @yegappan pushed 3 commits.

    • 397b4c4 Input redirection doesn't work with powershell
    • 04f9382 Optimize the check for the power shell name
    • 0e3946f Support powershell in Unix-like systems

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11204175481@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 12:31:39 AM10/3/22
    to vim/vim, Subscribed

    @yegappan commented on this pull request.


    In src/ex_cmds.c:

    > +	if (is_powershell)
    +	    len = (long_u)STRLEN(cmd) + 3;
    +	else
    +	    len = (long_u)STRLEN(cmd) + 3;			// "()" + NUL
    

    Yes. In the original patch, the length was set to zero. But that broke some other functionality. When I reverted that change, I forgot to remove this.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127787574@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 12:32:09 AM10/3/22
    to vim/vim, Subscribed

    @yegappan commented on this pull request.


    In src/ex_cmds.c:

    > +	    // "& { Get-Content" + " | & " + " }"
    +	    len += (long_u)STRLEN(itmp) + 23;
    

    Changed the value to 24.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127787780@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 12:32:36 AM10/3/22
    to vim/vim, Subscribed

    @yegappan commented on this pull request.


    In src/ex_cmds.c:

    >  #else
    -    // For shells that don't understand braces around commands, at least allow
    -    // the use of commands in a pipe.
    -    if (*p_sxe != NUL && *p_sxq == '(')
    +    if (is_powershell)
    

    Moved the powershell handling code to outside of the '#ifdef/#endif'.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/review/1127787951@github.com>

    Enan Ajmain

    unread,
    Oct 3, 2022, 1:58:05 AM10/3/22
    to vim/vim, Subscribed

    The patch now looks like it should be fine. I can't tell why the tests are failing (haven't looked at the test files yet).


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/c1264969323@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 2:05:14 AM10/3/22
    to vim/vim, Push

    @yegappan pushed 1 commit.

    • c4fa220 Input redirection doesn't work with powershell

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11204699297@github.com>

    Bram Moolenaar

    unread,
    Oct 3, 2022, 8:06:25 AM10/3/22
    to vim/vim, Subscribed


    The current patch checks for powershell on any system.
    It is available on Linux, but does it use exactly the same syntax then?
    Is it even practical to set 'shell' to powershell on any other system
    than MS-Windows?

    --
    hundred-and-one symptoms of being an internet addict:
    256. You are able to write down over 250 symptoms of being an internet
    addict, even though they only asked for 101.

    /// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
    /// \\\
    \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
    \\\ help me help AIDS victims -- http://ICCF-Holland.org ///


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/c1265343210@github.com>

    Enan Ajmain

    unread,
    Oct 3, 2022, 8:27:55 AM10/3/22
    to vim/vim, Subscribed

    It is available on Linux, but does it use exactly the same syntax then?

    There may be differences in some cases, but as far as I have used it I haven't found any.

    Is it even practical to set 'shell' to powershell on any other system
    than MS-Windows?

    I don't think so. First, practically no one will use it. Second, there are several bugs/oddities in pwsh in Linux: e.g., using sort with Start-Process sort -RedirectStandardInput in.txt works fine, but if we redirect it to a file (-RedirectStandardOutput out.txt) then it eats all the empty lines.

    But I want to leave it to the maintainer (you, Bram) to decide. We can always take the other choice later, if required; it's not a huge change.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/c1265367466@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 10:15:49 AM10/3/22
    to vim...@googlegroups.com, reply+ACY5DGBTX7BQMVHA35...@reply.github.com, vim/vim, Subscribed
    Hi Bram,

    On Mon, Oct 3, 2022 at 5:06 AM Bram Moolenaar <vim-dev...@256bit.org> wrote:


    The current patch checks for powershell on any system.
    It is available on Linux, but does it use exactly the same syntax then?
    Is it even practical to set 'shell' to powershell on any other system
    than MS-Windows?



    Setting 'shell' to 'pwsh' or 'powershell' (Powershell) was supported on Linux before
    this patch.  But "%!sort" was failing on Linux (just like on MS-Windows) before
    this patch.  This patch makes it work on both Linux and MS-Windows.

    - Yegappan

    vim-dev ML

    unread,
    Oct 3, 2022, 10:16:05 AM10/3/22
    to vim/vim, vim-dev ML, Your activity

    Hi Bram,

    On Mon, Oct 3, 2022 at 5:06 AM Bram Moolenaar ***@***.***>

    wrote:

    >
    > The current patch checks for powershell on any system.
    > It is available on Linux, but does it use exactly the same syntax then?
    > Is it even practical to set 'shell' to powershell on any other system
    > than MS-Windows?
    >
    >
    >
    Setting 'shell' to 'pwsh' or 'powershell' (Powershell) was supported on
    Linux before
    this patch. But "%!sort" was failing on Linux (just like on MS-Windows)
    before
    this patch. This patch makes it work on both Linux and MS-Windows.

    - Yegappan


    Reply to this email directly, view it on GitHub.

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/c1265510070@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 10:18:50 AM10/3/22
    to vim/vim, vim-dev ML, Push

    @yegappan pushed 1 commit.

    • b61f34d Input redirection doesn't work with powershell

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11209476235@github.com>

    Yegappan Lakshmanan

    unread,
    Oct 3, 2022, 10:28:38 AM10/3/22
    to vim/vim, vim-dev ML, Push

    @yegappan pushed 1 commit.

    • a6be157 Test filtering buffer contents through an external commands for all the shells

    You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11257/push/11209594107@github.com>

    Bram Moolenaar

    unread,
    Oct 3, 2022, 11:06:01 AM10/3/22
    to vim/vim, vim-dev ML, Comment

    Closed #11257 via 0a01667.


    Reply to this email directly, view it on GitHub.

    You are receiving this because you commented.Message ID: <vim/vim/pull/11257/issue_event/7508207850@github.com>

    Enan Ajmain

    unread,
    Oct 3, 2022, 12:19:46 PM10/3/22
    to vim_dev
    Thank you, Yegappan. Works beautifully.
    Reply all
    Reply to author
    Forward
    0 new messages