Last active
June 7, 2025 15:52
-
-
Save GustavoAmerico/799452cc34c15e6cd5b74d74c941031e to your computer and use it in GitHub Desktop.
This script should used for install help functions for work with git, azure cli and k8s. All ClI should be installed on the machine for helps works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $runAsElevated =($PSVersionTable.OS -match "Windows" -and [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")) -or | |
| ($PSVersionTable.OS -match "Linux" -and $EUID -eq 0); | |
| if($runAsElevated){ | |
| $ProfileFile = $($PROFILE | Select-Object AllUsersAllHosts).AllusersAllHosts; | |
| }else{ | |
| $ProfileFile = $($PROFILE | Select-Object CurrentUserAllHosts).CurrentUserAllHosts; | |
| } | |
| $ProfilePath = $ProfileFile.Substring(0, $ProfileFile.LastIndexOf("\") + 1); | |
| $FileExists = [System.IO.File]::Exists($ProfileFile); | |
| $helpOutput = ($ProfilePath + "GAmerico-Helps\"); | |
| $helpImportFileName="gamerico-helps.ps1"; | |
| $helpInstallFile=("$ProfilePath"+"$helpImportFileName"); | |
| if(Resolve-Path $helpOutput -ErrorAction SilentlyContinue){ | |
| $PathExists = $True; | |
| }else{ | |
| $PathExists = $False; | |
| } | |
| $urls = @( | |
| "https://gist.githubusercontent.com/GustavoAmerico/dd2da52b6a8b2da5db3df45bb0439d05/raw/git-help.ps1", | |
| "https://gist.githubusercontent.com/GustavoAmerico/9726b03880e13474d0a7c064dfb32372/raw/azurecli-help.ps1", | |
| "https://gist.githubusercontent.com/GustavoAmerico/f362a86581ed078e4e2178b2865cb348/raw/kubectl-help.ps1"); | |
| if (-not $PathExists) { | |
| mkdir -Force $helpOutput; | |
| } | |
| $urls | % { | |
| $url = $_; | |
| $helpFileName=($helpOutput+$_.Split(@("/"))[-1]); | |
| Invoke-WebRequest -Uri $url -OutFile $helpFileName | |
| } | |
| $helpFiles = (Get-ChildItem $helpOutput -Exclude $helpImportFileName).FullName; | |
| $fileLines = [System.String]::Join([System.Environment]::NewLine, ($helpFiles | % { (". """ + $_ + """;") })); | |
| $fileLines > $helpInstallFile; | |
| $fileContent= (". """ + $helpInstallFile + """").ToString(); | |
| if (-not $FileExists) { | |
| $fileContent > $ProfileFile; | |
| } | |
| else { | |
| # Check if import exists in the file profile | |
| if (Select-String -Path $ProfileFile -Pattern $helpInstallFile -SimpleMatch -Quiet) { | |
| Write-Output "The help import allready." | |
| } | |
| else { | |
| Write-Output ([System.Environment]::NewLine).ToString() | out-file -append -encoding utf8 $ProfileFile; | |
| Write-Output $fileContent | out-file -append -encoding utf8 $ProfileFile; | |
| Write-Output "The help import was added." | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Invoke-WebRequest -Uri "https://gist.githubusercontent.com/GustavoAmerico/799452cc34c15e6cd5b74d74c941031e/raw/install-gamerico-helps.ps1" -OutFile "$HOME\Downloads\install-gamerico-helps.ps1"; iex "$HOME\Downloads\install-gamerico-helps.ps1"