Skip to content

Commit 892c86c

Browse files
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 c0ea52f commit 892c86c

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
@@ -824,6 +824,10 @@ completion system:
824824
PS> foo --pwsh-completion-script (Get-Command foo).Source >> _foo.ps1
825825
PS> . _foo.ps1
826826
```
827+
You might want to add `Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete`
828+
to your powershell/pwsh profile in order to get better experience
829+
with completion tooltips.
830+
827831
Note for windows users - this will generate completion script for `foo.exe`,
828832
which is not equivalent to `foo` from tab-completion engine's point of view,
829833
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
@@ -275,19 +275,20 @@ pwshCompletionScript prog progn = return
275275
, ""
276276
, " $localCommand += '\"--bash-completion-index\"'"
277277
, " if ($wordToComplete.Equals(\"\")) {"
278-
, " $localCommand += '\"0\"'"
278+
, " $localCommand += '\"' + $commandAst.CommandElements.Count +'\"'"
279279
, " }"
280280
, " else {"
281281
, " $localCommand += '\"' + $hay.IndexOf($wordToComplete) + '\"'"
282282
, " }"
283283
, " $inp = & '" ++ prog ++ "' @localCommand"
284284
, " [CompletionResult[]]$out = @()"
285+
, " [string]$suffix = if ($inp.Count -eq 1) {' '} else {\"\"}"
285286
, " foreach ($item in $inp) {"
286287
, " $spl = $item.Split(\"`t\")"
287288
, " $show = $spl[0]"
288289
, " $tooltip = if ($spl.Length -eq 1) { $spl[0] } else { $spl[1] }"
289290
, " $crt = if ($show.StartsWith('-')) { [CompletionResultType]::ParameterName } else { [CompletionResultType]::ParameterValue }"
290-
, " $out += [CompletionResult]::new($show, $show.Trim('-'), $crt, $tooltip)"
291+
, " $out += [CompletionResult]::new($show + $suffix, $show, $crt, $tooltip)"
291292
, " }"
292293
, " $out"
293294
, "}"

0 commit comments

Comments
 (0)