nrfutil completion install powershell

When executing:

nrfutil completion install powershell

The output suggests adding this to $PROFILE

# From nrfutil completion install
# WARNING: nrfutil tab-completion may become slow because of Windows Defender
if ( Test-Path -Path ${USERPROFILE}\.nrfutil\share\nrfutil-completion\scripts\powershell\setup.ps1 ) {
    . ${USERPROFILE}\.nrfutil\share\nrfutil-completion\scripts\powershell\setup.ps1
}

I did some debuging to find out why the tab-completion does not work.
If I am not wrong the variable ${USERPROFILE} should be $env:USERPROFILE.
At least on my system (Windows 11, PowerShell 7.4) that was the solution.

Am I doing something wrong?

Parents
  • I am just opening a PowerShell Terminal.
    This opens in my $HOME directory, C:\Useres\myuser

    This also the location of .nrfutil
    I installed nrfutil with:

    winget install NordicSemiconductor.nrfutil
    
    Get-Command -Name nrfutil
    
    CommandType     Name                                               Version    Source
    -----------     ----                                               -------    ------
    Application     nrfutil.exe                                        0.0.0.0    C:\Users\timur\AppData\Local\Microsoft\WinGet\Packages\NordicSemiconductor.nrfutil_Microsoft.Winget.Source_8wekyb3d8bbwe\nrfutil.exe

    This is my $PROFILE where I had to add the $USERPROFILE manualy.

    # Set USERPROFILE
    $USERPROFILE = $env:USERPROFILE
    
    Invoke-Expression -Command $(gh completion -s powershell | Out-String)
    # Aliases
    Set-Alias -Name ll -Value Get-ChildItem -Force
    
    # Powershell Modules
    Import-Module posh-git
    
    Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
    
    # WARNING: nrfutil tab-completion may become slow because of Windows Defender
    # From nrfutil completion install
    if ( Test-Path -Path ${USERPROFILE}\.nrfutil\share\nrfutil-completion\scripts\powershell\setup.ps1 ) {
        . ${USERPROFILE}\.nrfutil\share\nrfutil-completion\scripts\powershell\setup.ps1
     }
    else {
        Write-Host "⚠️ The nrfutil completion script does not exist."
        exit
    }

  • Hi,

    xigit said:
    This is my $PROFILE where I had to add the $USERPROFILE manualy.

    Where is the location of your $PROFILE?

    Could you show the places where you needed to add $USERPROFILE manually?

    Best regards,
    Dejan

  • Hi,

    When you run setup script, you installed nrfutil and its tools, as well as made $PROFILE file, and then you manually added first line shown previously in your $PROFILE file. Is this correct?

    Could you show with example how tab-completion works for you before and after adding $USERPROFILE line in $PROFILE file?

    Best regards,
    Dejan

  • ? The Variable $USERPROFILE does not exist therefore tab completions can not work because the script is not found.
    I just tested " echo  $USERPROFILE" on another Windows machine and it does not exist.
    I think the output of nrfutil is wrong and should be changed to : 

    $env:USERPROFILE
  • This should be the output of:
    nrfutil completion install powershell
    ------
    
    # WARNING: nrfutil tab-completion may become slow because of Windows Defender
    # From nrfutil completion install
    if ( Test-Path -Path ${env:USERPROFILE}\.nrfutil\share\nrfutil-completion\scripts\powershell\setup.ps1 ) {
        . ${env:USERPROFILE}\.nrfutil\share\nrfutil-completion\scripts\powershell\setup.ps1
     }

  • Hi,

    I was not able to reproduce this on Windows 10. I have made an internal inquiry. I will get back to you by the end of next week.

    Best regards,
    Dejan

  • Hi,

    This issue likely arose from the change made in PowerShell related to the access to environment variables. The completion system was most probably developed using newer version of PowerShell which allows access to environment variables directly, which made "env" optional.
    It might be that you used older version of PowerShell although you have v7.4 installed on your system. You can check the actual version by running $PSVersionTable.

    Best regards,
    Dejan

Reply
  • Hi,

    This issue likely arose from the change made in PowerShell related to the access to environment variables. The completion system was most probably developed using newer version of PowerShell which allows access to environment variables directly, which made "env" optional.
    It might be that you used older version of PowerShell although you have v7.4 installed on your system. You can check the actual version by running $PSVersionTable.

    Best regards,
    Dejan

Children
Related