choco commands in PowerShell windows don't autocomplete.
choco commands in PowerShell windows should autocomplete.
I installed Chocolatey in a PowerShell administrator prompt. I noted the error saying:
Not setting tab completion: Profile file does not exist at 'C:\Users\MyName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
I quickly found out that the error was important to autocomplete not working, and tried looking for a solution on your FAQ. I followed the instructions here, but nothing worked. Below, I have attached a log of everything logged in the PowerShell window at the time of the incident, showing that I went through all of the steps on the FAQ.
Once I did so, I realized that no .ps1 file was created in the directory outputted. Is there any way to generate this file?
~~~sh PS C:\Windows\system32> . $profile The term 'C:\Users\MyName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:3 + . $profile + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\MyName\Doc...ell_profile.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Windows\system32> Set-ExecutionPolicy Bypass -Scope Process Execution Policy Change The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y PS C:\Windows\system32> type $profile type : Cannot find path 'C:\Users\MyName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1' because it does not exist. At line:1 char:1 + type $profile + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\MyName\Doc...ell_profile.ps1:String) [Get-Content], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand PS C:\Windows\system32> Write-Host $profile C:\Users\MyName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 PS C:\Windows\system32> . $profile The term 'C:\Users\MyName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:3 + . $profile + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\MyName\Doc...ell_profile.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Windows\system32> ~~~
The documentation indicates you're expected to create the file using a text editor (Notepad works fine, just make sure you save the file with a ps1 extension and not as a text file).
The quick and dirty way to do it is to pull the code listed on the docs page you referenced and tell PowerShell to create the file for you:
@'
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
'@ | Add-Content -Path $profile
Then you can use . $profile to reload the profile, or just reload the powershell session to have it load it in. ๐
The documentation indicates you're expected to create the file using a text editor (Notepad works fine, just make sure you save the file with a ps1 extension and not as a text file).
The quick and dirty way to do it is to pull the code listed on the docs page you referenced and tell PowerShell to create the file for you:
@'Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
'@ | Add-Content -Path $profile
Then you can use . $profile to reload the profile, or just reload the powershell session to have it load it in. ๐
Oh, ok, I didn't pick up on the fact that we were supposed to manually create the .ps1 file because of the wording used in the documentation. That makes a lot more sense. I'll test this when I get back in front of my PC tomorrow morning, but I'm expecting your solution to work.
Thank you again for your help!
@vexx32 Your solution worked. Thank you very much!
To recap, for anyone facing this issue afterwards:
1) If you have issues with PowerShell autocompletion using choco, make sure to follow the documentation linked here.
2) When you get to the part of the documentation containing the code snippet, create the .ps1 file in the WindowsPowerShell directory yourself. PowerShell will not do this for you, and the documentation doesn't make this clear, in my opinion.
3) After you have created the file manually and pasted the code provided in the documentation snippet, save it, and run . $profile in PowerShell. If you've done this correctly, you won't see any error messages.
Might be worth changing that doc a bit to make it more clear. I might submit a PR for it after Christmas/new year, or you're welcome to as well. ๐
Ok, great! I'll definitely look into it.
On Tue, Dec 24, 2019, 2:21 PM vexx32 notifications@github.com wrote:
Might be worth changing that doc a bit to make it more clear. I might
submit a PR for it after Christmas/new year, or you're welcome to as well.
๐โ
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/chocolatey/choco/issues/1971?email_source=notifications&email_token=AEF6PQUQ4B7GDGRAD5XB3YDQ2JOL7A5CNFSM4J6ZDHL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHTRUMQ#issuecomment-568793650,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEF6PQWDEYNC4O37EYJUG2DQ2JOL7ANCNFSM4J6ZDHLQ
.
@vexx32 or @mariobrostech I reopened this for now to see if there is documentation to submit.
Might be worth changing that doc a bit to make it more clear. I might submit a PR for it after Christmas/new year, or you're welcome to as well. ๐
@vexx32 Hey, I know it's been quite some time since there's been any activity on this issue, but I just wanted to check in. Did you ever getting around to looking into this more or submitting feedback to improve the documentation?
I don't think I did, but thanks for the reminder! I have some downtime so I'll probably just go make those additions now.
Fantastic, let me know how it goes!
Most helpful comment
@vexx32 Your solution worked. Thank you very much!
To recap, for anyone facing this issue afterwards:
1) If you have issues with PowerShell autocompletion using
choco, make sure to follow the documentation linked here.2) When you get to the part of the documentation containing the code snippet, create the
.ps1file in theWindowsPowerShelldirectory yourself. PowerShell will not do this for you, and the documentation doesn't make this clear, in my opinion.3) After you have created the file manually and pasted the code provided in the documentation snippet, save it, and run
. $profilein PowerShell. If you've done this correctly, you won't see any error messages.