File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 52
52
//!
53
53
//! Powershell
54
54
//! ```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
56
58
//! ```
57
59
//!
58
60
//! Zsh
Original file line number Diff line number Diff line change @@ -274,13 +274,25 @@ impl EnvCompleter for Powershell {
274
274
let completer =
275
275
shlex:: try_quote ( completer) . unwrap_or ( std:: borrow:: Cow :: Borrowed ( completer) ) ;
276
276
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
277
280
writeln ! (
278
281
buf,
279
282
r#"
280
283
Register-ArgumentCompleter -Native -CommandName {bin} -ScriptBlock {{
281
284
param($wordToComplete, $commandAst, $cursorPosition)
282
285
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
+ }}
284
296
$results | ForEach-Object {{
285
297
$split = $_.Split("`t");
286
298
$cmd = $split[0];
You can’t perform that action at this time.
0 commit comments