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

  • 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

  • Hi,

    Reported issue has been fixed. 

    Best regards,
    Dejan

  • Does that mean the fix will be in the next version of nrfutil?
    Or is my case a corner case and the variable access via $USERRPOFILE should work without the optional "env" context

Reply Children
  • Hi,

    A new version of "nrfutil-completion" has been released. New release can be installed by running "nrfutil install completion".

    You do not need to do anything since everything works as expected for you with your modifications. However, you might want to use official version.

    Regarding the fix for PowerShell, the output for $PROFILE now accesses the path to the home directory using associated environment variable ($env:USERPROFILE/$env:HOME). Previously, script assumed that environment variables were accessible as normal variables ($USERPROFILE/$HOME), but this is only valid for newer versions of PowerShell.

    Best regards,
    Dejan

Related