Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile command - add tab completion/refreshenv to PowerShell #894

Open
ferventcoder opened this issue Aug 6, 2016 · 8 comments
Open

Profile command - add tab completion/refreshenv to PowerShell #894

ferventcoder opened this issue Aug 6, 2016 · 8 comments
Assignees
Milestone

Comments

@ferventcoder
Copy link
Member

This is a split off of #833.

@masaeedu
Copy link

I'm trying to understand if refreshenv for powershell has been removed as a feature. If not, what is the correct way to load it? A few weeks ago you had to reload your profile, but it seems the profile is no longer updated.

@ferventcoder
Copy link
Member Author

@masaeedu it's still there as a feature, you just may need to manually add it. We introduced #833 to address the issues of creating a profile in many automation scenarios.

To add it manually for now when you install and there isn't a profile found or the profile file is missing.

$profileInstall = @'
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
    Import-Module "$ChocolateyProfile"
}
'@

$profileFile = "$profile"
$chocoProfileSearch = '$ChocolateyProfile'
if(Select-String -Path $profileFile -Pattern $chocoProfileSearch -Quiet -SimpleMatch) {
    Write-Debug "Chocolatey profile is already installed."
    return
}

$profileInstall | Out-File $profileFile -Append -Encoding (Get-FileEncoding $profileFile)

@ferventcoder ferventcoder modified the milestones: 0.10.9, 0.10.10 Aug 29, 2017
@flcdrg
Copy link
Member

flcdrg commented Sep 20, 2017

So just clarifying - this issue is about adding a new command to choco.exe that will add the Chocolatey bits to your PowerShell profile. This is for the scenario when you didn't have a $profile file when you first installed Chocolatey, and so the installer skipped that step.

@ferventcoder
Copy link
Member Author

@flcdrg yes, that's the idea.

@dasjestyr
Copy link

Get-FileEncoding doesn't appear to be a standard module. Where can I get this?

@ferventcoder ferventcoder modified the milestones: 0.10.10, 0.10.11, 0.10.12 Mar 27, 2018
@flcdrg
Copy link
Member

flcdrg commented Mar 27, 2018

@ferventcoder ferventcoder modified the milestones: 0.10.12, 0.10.13 May 3, 2018
@ferventcoder ferventcoder modified the milestones: 0.10.13, 0.10.14, 0.10.15 Mar 9, 2019
@ferventcoder ferventcoder modified the milestones: 0.10.15, 0.10.16 Apr 1, 2019
@gep13 gep13 modified the milestones: 0.10.16, 0.10.17 May 31, 2019
@ctmcisco
Copy link

Hey Chocolatey Team, I was fussing around with Powershell 7 Preview and added a function to my $PROFILE, actually related to Chocolatey. I tried running it this morning and found my function didn't work.

In troubleshooting I found that my $profile was modified with a Chocolatey Profile script. First off I think I have done a disservice to Choco as I didn't realize there was tab completion until today. When researching this I have been missing this since 2016, Yikes!
So something happened to my function and in its place the tab completion script. Not a big deal just wanted to add a comment about it here.

Anyhow it is awesome to have this feature.

@ferventcoder ferventcoder modified the milestones: 0.10.17, 0.10.18 Jan 14, 2020
@ferventcoder ferventcoder modified the milestones: 0.10.18, 0.10.x Apr 14, 2021
@Beej126
Copy link

Beej126 commented Aug 27, 2021

here's tweaked Get-FileEncoding that works for pwsh 7.1.4

function Get-FileEncoding($Path) {
     $bytes = [byte[]]((Get-Content $Path -AsByteStream -Raw -ReadCount 4)[0])

     if(!$bytes) { return 'utf8' }

     switch -regex ('{0:x2}{1:x2}{2:x2}{3:x2}' -f $bytes[0],$bytes[1],$bytes[2],$bytes[3]) {
         '^efbbbf'   { return 'utf8' }
         '^2b2f76'   { return 'utf7' }
         '^fffe'     { return 'unicode' }
         '^feff'     { return 'bigendianunicode' }
         '^0000feff' { return 'utf32' }
         default     { return 'ascii' }
     }
}

@corbob corbob self-assigned this Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants