Skip to content

Commit 1b96004

Browse files
ShrykeWindgraceHuwCampbell
authored andcommitted
Address various issues spotted by @HuwCampbell:
- add note on `PSReadline` settings in order to get tooltips - do not trim dashes in option names - fix command index if we are completing an "empty word" - add space if we are trying to complete a full word
1 parent 4cb2056 commit 1b96004

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ completion system:
834834
PS> foo --pwsh-completion-script (Get-Command foo).Source >> _foo.ps1
835835
PS> . _foo.ps1
836836
```
837+
You might want to add `Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete`
838+
to your powershell/pwsh profile in order to get better experience
839+
with completion tooltips.
840+
837841
Note for windows users - this will generate completion script for `foo.exe`,
838842
which is not equivalent to `foo` from tab-completion engine's point of view,
839843
even though from usage point view they are equivalent. You might want to edit

src/Options/Applicative/BashCompletion.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,20 @@ pwshCompletionScript prog progn = unlines
282282
, ""
283283
, " $localCommand += '\"--bash-completion-index\"'"
284284
, " if ($wordToComplete.Equals(\"\")) {"
285-
, " $localCommand += '\"0\"'"
285+
, " $localCommand += '\"' + $commandAst.CommandElements.Count +'\"'"
286286
, " }"
287287
, " else {"
288288
, " $localCommand += '\"' + $hay.IndexOf($wordToComplete) + '\"'"
289289
, " }"
290290
, " $inp = & '" ++ prog ++ "' @localCommand"
291291
, " [CompletionResult[]]$out = @()"
292+
, " [string]$suffix = if ($inp.Count -eq 1) {' '} else {\"\"}"
292293
, " foreach ($item in $inp) {"
293294
, " $spl = $item.Split(\"`t\")"
294295
, " $show = $spl[0]"
295296
, " $tooltip = if ($spl.Length -eq 1) { $spl[0] } else { $spl[1] }"
296297
, " $crt = if ($show.StartsWith('-')) { [CompletionResultType]::ParameterName } else { [CompletionResultType]::ParameterValue }"
297-
, " $out += [CompletionResult]::new($show, $show.Trim('-'), $crt, $tooltip)"
298+
, " $out += [CompletionResult]::new($show + $suffix, $show, $crt, $tooltip)"
298299
, " }"
299300
, " $out"
300301
, "}"

0 commit comments

Comments
 (0)