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,

    How was your $PROFILE file created?

    Best regards,
    Dejan

  • I have a setup script.
    It's the first thing that is created.

    # Check if the user's PowerShell profile exists, and create it if it doesn't
      if (!(Test-Path -Path $PROFILE)) {
        New-Item -ItemType File -Path $PROFILE -Force
        Write-Host "Created new profile"
      }
      else {
        Write-Host "PowerShell profile already exists"
      }
    
    # Check if git the command is available, and install it if it isn't
      if (!(Get-Command -Name git -ErrorAction SilentlyContinue)) {
        Write-Host "Git not found, installing..."
        winget install -e --id=Git.Git
      }
      else {
        Write-Host "Git already installed"
      }
    # Check if the git user config exists, and create it if it doesn't
      if (!(git config --get user.name)) {
        Write-Host "Git user.name not set, setting..."
        git config --global user.name "T"
        git config --global user.email "[email protected]"
      }
    
    # Print the current git user config
      Write-Host "Git user: $(git config --get user.name)"
      Write-Host "Git email: $(git config --get user.email)"
    
    # Test SSH connection to GitHub
    $sshOutput = Invoke-Expression 'ssh -T [email protected]'
    
    # Check if the SSH connection was successful
    if ($sshOutput -match 'successfully authenticated') {
      Write-Host '✅SSH connection to GitHub successful'
    } else {
      Write-Host 'SSH connection to GitHub failed'
      Write-Host $sshOutput
      Write-Host 'Make sure your SSH key is added to your GitHub account'
    }
    
    # Check if github cli is intalled and install if not
    if (!(Get-Command -Name gh -ErrorAction SilentlyContinue)) {
      Write-Host "GitHub CLI not found, installing..."
      winget install -e --id=GitHub.cli
    }
    else {
      Write-Host "GitHub CLI already installed"
      Write-Host "Checking if the completion script is installed..."
      if (!(Select-String -Path $PROFILE -Pattern "gh completion -s powershell")) {
        Write-Host "GitHub CLI completion script not installed, installing..."
        # Append gh completion command to PowerShell profile
        $profilePath = $PROFILE
        Add-Content -Path $profilePath -Value "`nInvoke-Expression -Command `$(`gh completion -s powershell` | Out-String)"
        Write-Host "GitHub CLI completion script installed"
      }
      else {
        Write-Host "✅GitHub CLI completion script already installed"
      }
    }
    
    ### CHOCOLATEY ###
    # Check if chocolatey is installed and install if not
    if (!(Get-Command -Name choco -ErrorAction SilentlyContinue)) {
      Write-Host "Chocolatey not found, installing..."
      winget install -e --id=Chocolatey.Chocolatey
    }
    else {
      Write-Host "✅Chocolatey already installed"
    }
    
    ### POSH-GIT ###
    # Check if posh-git is installed and install if not
    if (!(Get-Module -ListAvailable -Name posh-git)) {
      Write-Host "posh-git not found, installing..."
      # (A) You've never installed posh-git from the PowerShell Gallery
      PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force
    }
    else {
      Write-Host "✅posh-git already installed"
    }
    
    ### NORDIC SEMICONDUCTOR ###
    # Check if nrfutil is installed and install if not
    if (!(Get-Command -Name nrfutil -ErrorAction SilentlyContinue)) {
      Write-Host "nrfutil not found, installing..."
      winget install NordicSemiconductor.nrfutil
    }
    else {
      Write-Host "✅nrfutil already installed"
    }
    
    # Install nrfutil tools
    nrfutil install device
    nrfutil install completion
    nrfutil install toolchain-manager
    
    # Configure nrfutil completion
    # Check if the nrfutil completion script is installed, and install it if it isn't
    if (!(Select-String -Path $PROFILE -Pattern "From nrfutil completion install")) {
      Write-Host "⚠️ nrfutil completion script not installed"
      Write-Host "Follow the instructions below to install it:"
      nrfutil completion install powershell
      Write-Host "⚠️ Re-run this script after installing the completion script"
      exit
    }
    else {
      Write-Host "✅nrfutil completion script already installed"
    }
    

  • 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
     }

Reply Children
Related