mirror of
https://github.com/neovim/neovim.git
synced 2025-09-20 02:08:17 +00:00
fix: :! pwsh redirection for command not found
Problem:
If the shell command passed to the filtered bang command isn't found,
the error isn't redirected to the temp.out file when shell is set to
powershell.
Solution: Use anonymous function with Invoke-Command operator (&).
(cherry picked from commit f2482b3b53
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
bb9c5c3f60
commit
ce422ba763
@@ -1549,7 +1549,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp)
|
|||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
if (itmp != NULL) {
|
if (itmp != NULL) {
|
||||||
len += is_pwsh ? strlen(itmp) + sizeof("Get-Content " " | & ") - 1
|
len += is_pwsh ? strlen(itmp) + sizeof("& { Get-Content " " | & " " }") - 1
|
||||||
: strlen(itmp) + sizeof(" { " " < " " } ") - 1;
|
: strlen(itmp) + sizeof(" { " " < " " } ") - 1;
|
||||||
}
|
}
|
||||||
if (otmp != NULL) {
|
if (otmp != NULL) {
|
||||||
@@ -1560,10 +1560,11 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp)
|
|||||||
|
|
||||||
if (is_pwsh) {
|
if (is_pwsh) {
|
||||||
if (itmp != NULL) {
|
if (itmp != NULL) {
|
||||||
xstrlcpy(buf, "Get-Content ", len - 1); // FIXME: should we add "-Encoding utf8"?
|
xstrlcpy(buf, "& { Get-Content ", len - 1); // FIXME: should we add "-Encoding utf8"?
|
||||||
xstrlcat(buf, (const char *)itmp, len - 1);
|
xstrlcat(buf, (const char *)itmp, len - 1);
|
||||||
xstrlcat(buf, " | & ", len - 1); // FIXME: add `&` ourself or leave to user?
|
xstrlcat(buf, " | & ", len - 1); // FIXME: add `&` ourself or leave to user?
|
||||||
xstrlcat(buf, cmd, len - 1);
|
xstrlcat(buf, cmd, len - 1);
|
||||||
|
xstrlcat(buf, " }", len - 1);
|
||||||
} else {
|
} else {
|
||||||
xstrlcpy(buf, cmd, len - 1);
|
xstrlcpy(buf, cmd, len - 1);
|
||||||
}
|
}
|
||||||
|
@@ -642,12 +642,12 @@ describe('shell :!', function()
|
|||||||
if iswin() then
|
if iswin() then
|
||||||
feed(':4verbose %!sort /R<cr>')
|
feed(':4verbose %!sort /R<cr>')
|
||||||
screen:expect{
|
screen:expect{
|
||||||
any=[[Executing command: .?Get%-Content .* | & sort /R 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]]
|
any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]]
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
feed(':4verbose %!sort -r<cr>')
|
feed(':4verbose %!sort -r<cr>')
|
||||||
screen:expect{
|
screen:expect{
|
||||||
any=[[Executing command: .?Get%-Content .* | & sort %-r 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]]
|
any=[[Executing command: .?& { Get%-Content .* | & sort %-r } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
feed('<CR>')
|
feed('<CR>')
|
||||||
|
Reference in New Issue
Block a user