Adding tab-completion to your PowerShell Functions
utterances-bot opened this issue · 3 comments
Adding tab-completion to your PowerShell Functions
FoxDeploy.com, Stephen Owen's technical blog about
PowerShell, Systems Administration, GUI Design and Programming.
.
https://www.foxdeploy.com/blog/adding-tab-completion-to-your-powershell-functions.html
I'm able to do tab completion for the parameter and the parameter values while running the command from the script pane.
function Hello-World
{param( [ValidateSet('Green','Red','Blue')] $Color)
Write-Host "Hello world!" -Foreground $Color
}
However, tab completion doesn't work when the file is in the Scripts folder like other scripts installed using Install-Script
.
$DestPath = [Environment]::GetFolderPath('MyDocuments')+"\PowerShell\Scripts"
(New-Object System.Net.WebClient).DownloadFile("https://github.com/Ayanmullick/test/raw/master/Hello-World.ps1","$DestPath\Hello-World.ps1")
Invoke-Expression "$DestPath\Hello-World.ps1"
I'm able to do tab completion for the parameter and the parameter values while running the command from the script pane.
function Hello-World {param( [ValidateSet('Green','Red','Blue')] $Color) Write-Host "Hello world!" -Foreground $Color }However, tab completion doesn't work when the file is in the Scripts folder like other scripts installed using
Install-Script
.$DestPath = [Environment]::GetFolderPath('MyDocuments')+"\PowerShell\Scripts" (New-Object System.Net.WebClient).DownloadFile("https://github.com/Ayanmullick/test/raw/master/Hello-World.ps1","$DestPath\Hello-World.ps1") Invoke-Expression "$DestPath\Hello-World.ps1"
Removing the function wrapper in the file being downloaded and adding the default script folder path to $env:PATH
resolved the issue.
If (($env:PATH -split ';') -notcontains $DestPath) {$env:Path += ";$DestPath"}