File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 5252//!
5353//! Powershell
5454//! ```powershell
55- //! echo "COMPLETE=powershell your_program | Invoke-Expression" >> $PROFILE
55+ //! $env:COMPLETE = "powershell"
56+ //! echo "your_program | Out-String | Invoke-Expression" >> $PROFILE
57+ //! Remove-Item Env:\COMPLETE
5658//! ```
5759//!
5860//! Zsh
Original file line number Diff line number Diff line change @@ -274,13 +274,25 @@ impl EnvCompleter for Powershell {
274274 let completer =
275275 shlex:: try_quote ( completer) . unwrap_or ( std:: borrow:: Cow :: Borrowed ( completer) ) ;
276276
277+ // `completer` may or may not be surrounded by double quotes, enclosing
278+ // the expression in a here-string ensures the whole thing is
279+ // interpreted as the first argument to the call operator
277280 writeln ! (
278281 buf,
279282 r#"
280283Register-ArgumentCompleter -Native -CommandName {bin} -ScriptBlock {{
281284 param($wordToComplete, $commandAst, $cursorPosition)
282285
283- $results = Invoke-Expression "{var}=powershell &{completer} -- $($commandAst.ToString())";
286+ $prev = $env:{var};
287+ $env:{var} = "powershell";
288+ $results = Invoke-Expression @"
289+ & {completer} -- $commandAst
290+ "@;
291+ if ($null -eq $prev) {{
292+ Remove-Item Env:\{var};
293+ }} else {{
294+ $env:{var} = $prev;
295+ }}
284296 $results | ForEach-Object {{
285297 $split = $_.Split("`t");
286298 $cmd = $split[0];
You can’t perform that action at this time.
0 commit comments