powershellpdflatextab-completion

PowerShell 7 autocompletion adds .\ to the file name in the current folder... which is sometimes a problem


I use pdflatex from the PowerShell 7 terminal on Windows 11.

When I press "tab" to autocomplete the name of the file in the current folder, it adds .\ at the begining (for example, I get pdflatex .\filename.tex), which pdflatex does not understand. Hence, I have to move the cursor, remove the .\ at the begining, and then press enter, which is not very confortable since the idea of using tab in the first pleace is to write less. What can I do?

I am using PowerShell 7.4.1 and pdflatex 3.141592653-2.6-1.40.25 (Tex Live 2023) with kpathsea version 6.3.5.

Step by step to reproduce the problem.

> pdflatex .\filename.tex
This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
! Undefined control sequence.
<*> .\filename
          .tex
?

Solution

  • Presumably you're looking for completion of .tex files in the current location without the .\ in which case you can use Register-ArgumentCompleter with the -Native switch:

    Register-ArgumentCompleter -CommandName pdflatex -Native -ScriptBlock {
        param($wordToComplete, $commandAst, $cursorPosition)
    
        Get-ChildItem -Filter *.tex |
            Where-Object { $_.Name.StartsWith($wordToComplete, [StringComparison]::InvariantCulture) } |
            ForEach-Object Name
    }