Last active
January 28, 2025 03:31
-
-
Save steviecoaster/bd0bb8681c150279cb23d2e3ca8b2871 to your computer and use it in GitHub Desktop.
My PowerShell Profile script
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
function Get-OutdatedChocoPackage { | |
[Alias('outdated')] | |
[Cmdletbinding()] | |
Param( | |
) | |
choco outdated --limit-output | | |
ConvertFrom-Csv -Delimiter '|' -Header Id, InstalledVersion, AvailableVersion, Pinned | | |
Select-Object Id, InstalledVersion, AvailableVersion, @{N = 'Pinned'; E = { [Bool]::Parse($_.Pinned) } } | | |
Where-Object { [version]$_.AvailableVersion -gt [version]$_.InstalledVersion } | |
} | |
function ConvertTo-StarDate { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[DateTime] | |
$Date | |
) | |
end { | |
# Gregorian bullshit to get # of days in the given year | |
$cal = [System.Globalization.GregorianCalendar]::new() | |
$DaysInYear = $cal.GetDaysInYear($Date.Year) | |
$DayOfYear = $Date.DayOfYear | |
$step1 = 1000 * ($Date.Year - 2323) | |
$step2 = ($DayOfYear / $DaysInYear) * 1000 | |
$step3 = $step1 + $step2 | |
[math]::Round($step3, 2) | |
} | |
} | |
function Convert-GitRemote { | |
[CmdletBinding()] | |
Param() | |
end { | |
$matcher = '^(?<Name>\S+)\s+(?<Url>\S+)\s+\((?<Type>\S+)\)$' | |
$output = git remote -v | |
foreach ($line in $output) { | |
$null = $line -match $matcher | |
[pscustomobject]@{ | |
Name = $Matches.Name | |
Url = ($Matches.Url).Trim('.git') | |
Type = $matches.type | |
} | |
} | |
} | |
} | |
function Open-GitRemote { | |
[Alias('ogr')] | |
[CmdletBinding()] | |
Param( | |
[Parameter()] | |
[String] | |
$Name = 'origin', | |
[Parameter()] | |
[ValidateSet('fetch', 'push')] | |
[String] | |
$Type = 'fetch' | |
) | |
end { | |
$remotes = Convert-GitRemote | |
$url = ($remotes | Where-Object Type -eq $Type).Url | |
Start-Process $url | |
} | |
} | |
function Get-Bourbon { | |
[CmdletBinding()] | |
Param( | |
[Parameter()] | |
[String[]] | |
$Choice = @('Buffalo Trace', 'Weller', 'Dickle Bonded', 'Envy', 'Statesman', 'Forester Bonded', 'Blantons', 'Bardstown Wheated', 'Bardstown SB', 'Bardstown Rye', 'Sazarac', 'Michters Rye', 'Isaac Bowman', 'Koval') | |
) | |
end { | |
$Choice | Get-Random | |
} | |
} | |
function Open-CertPath { | |
[Alias('cert')] | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[String] | |
$Domain | |
) | |
process { | |
Invoke-Item (Split-Path -Parent (Get-PACertificate -MainDomain $Domain).PfxFile) | |
} | |
} | |
function New-GitBranch { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory,Position=0)] | |
[String] | |
$Branch, | |
[Parameter(Mandatory,Position=1)] | |
[String] | |
$Trunk | |
) | |
process { | |
switch($Trunk){ | |
'master' { | |
$commandArgs = [ordered]@{ | |
Fetch = @('fetch','upstream') | |
Checkout = @('checkout', 'master') | |
Rebase = @('rebase','upstream/master') | |
Push = @('push','origin') | |
Branch = @('checkout','-b',$Branch) | |
} | |
} | |
'main' { | |
$commandArgs = [ordered]@{ | |
Fetch = @('fetch','upstream') | |
Checkout = @('checkout', 'main') | |
Rebase = @('rebase','upstream/main') | |
Push = @('push','origin') | |
Branch = @('checkout','-b',$Branch) | |
} | |
} | |
} | |
$commandArgs.GetEnumerator() | ForEach-Object { | |
$array = @($_.Value) | |
& git @array | |
} | |
} | |
} | |
function Invoke-Lab { | |
[Alias('lab')] | |
[CmdletBinding()] | |
Param( | |
[Parameter(Position=0,Mandatory)] | |
[ValidateSet('start','quit')] | |
[String] | |
$Action | |
) | |
process { | |
switch($Action){ | |
'start'{ | |
Start-VagrantEnvironment QSG ; Start-VagrantEnvironment TestEnv | |
} | |
'quit' { | |
Stop-VagrantEnvironment TestEnv ; Stop-VagrantEnvironment QSG | |
} | |
} | |
} | |
} | |
function Pop-LELocation { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[String] | |
$Domain | |
) | |
process { | |
Push-Location (Split-Path -Parent (Get-PACertificate -MainDomain $Domain).PfxFile) | |
} | |
} | |
function Start-ChocoBuild { | |
[cmdletBinding()] | |
Param( | |
[Parameter()] | |
[ValidateSet('Debug','Official')] | |
[String] | |
$Type = 'Debug' | |
) | |
process { | |
Write-Verbose "Building from $PWD" | |
$buildType = Switch ($Type) { | |
'Debug' { 'build.debug.sh'} | |
'Official' { 'build.official.sh'} | |
} | |
$dockerArgs = @('build','-t','choco:latest-linux', '-f','docker/Dockerfile.linux','.','--build-arg',"buildscript=$buildType") | |
& docker @dockerArgs | |
} | |
} | |
function Start-ChocoContainer { | |
[CmdletBinding()] | |
Param() | |
process { | |
Write-Verbose "Running from $PWD" | |
$dockerArgs = @('run','-ti','--rm','choco:latest-linux','/bin/bash') | |
docker @dockerArgs | |
} | |
} | |
function Get-DadJoke { | |
[cmdletBinding()] | |
Param() | |
process { | |
$header = @{ | |
Accept = "application/json" | |
} | |
$joke = Invoke-RestMethod -Uri "https://icanhazdadjoke.com/" -Method Get -Headers $header | |
$joke.joke | |
} | |
} | |
Function prompt { | |
$fullPath = $ExecutionContext.SessionState.Path.CurrentLocation -split ('/') | |
"PS | $((Get-Date).ToShortTimeString()) | $($fullpath | select-Object -Last 1)$('>' * ($nestedPromptLevel + 1)) " | |
} | |
Function Pop-GH { | |
[Alias('pgh')] | |
[cmdletBinding()] | |
Param( | |
[Parameter()] | |
[String] | |
$Uri = "https://github.com/steviecoaster" | |
) | |
start-Process $uri | |
} | |
function Update-BoxLink { | |
[Alias('ubl')] | |
[cmdletBinding()] | |
Param( | |
[Parameter(Mandatory, Position = 0)] | |
[String] | |
$Link | |
) | |
$NewLink = $($link -replace ("/s/", "/shared/static/")) + ".nupkg" | |
$NewLink | Set-Clipboard | |
Write-Host "$NewLink has been placed on your clipboard" -ForegroundColor Blue | |
} | |
function ConvertTo-ChocoObject { | |
[CmdletBinding()] | |
Param ( | |
[Parameter(ValueFromPipeline)] | |
[string]$InputObject | |
) | |
Process { | |
# format of the 'choco list' output is: | |
# <PACKAGE NAME> <VERSION> (ie. adobereader 2015.6.7) | |
if (-not [string]::IsNullOrEmpty($InputObject)) { | |
$props = $_.split('|') | |
If (-not $audit) { | |
[pscustomobject]@{ | |
name = $props[0] | |
version = $props[1] | |
} | |
} | |
Else { | |
[pscustomobject]@{ | |
name = $props[0] | |
version = $props[1] | |
InstalledBy = $props[2] -replace ('User:', '') | |
Domain = $props[3] -replace ('Domain:', '') | |
RequestedBy = $props[4] -replace ('Original User:', '') | |
'InstallDate(UTC)' = $props[5] -replace ('InstallDateUtc:', '') | |
} | |
} | |
} | |
} | |
} | |
Function Open-GitRepo { | |
<# | |
.SYNOPSIS | |
Changes your $pwd to the directory of the requested repo name | |
.DESCRIPTION | |
Changes your $pwd to the directory of the requested repo name | |
.PARAMETER Repo | |
The repo to open | |
.EXAMPLE | |
Open-GitRepo -Repo SuperAwesomeProject | |
#> | |
[Alias("Goto")] | |
[cmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[ArgumentCompleter( | |
{ | |
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) | |
$user_profile = if($isMacOS){ | |
$env:HOME | |
} else { | |
$env:USERPROFILE | |
} | |
$results= Get-ChildItem "$user_profile\Documents\git\ChocoStuff" -Directory | Select-Object -ExpandProperty Name | |
If ($WordToComplete) { | |
$results.Where{ $_ -match "^$WordToComplete" } | |
} | |
Else { | |
$results | |
} | |
} | |
)] | |
[String] | |
$Repo | |
) | |
process { | |
$user_profile = if($isMacOS){ | |
$env:HOME | |
} else { | |
$env:USERPROFILE | |
} | |
$path = (Get-ChildItem "$user_profile\Documents\git\ChocoStuff" -Directory | Where-Object { $_.FullName -match "$Repo" }).FullName | |
Push-Location $path | |
} | |
} | |
function Get-DaysToSummit { | |
[CmdletBinding()] | |
Param( | |
[Parameter()] | |
[DateTime] | |
$StartDate | |
) | |
$days = (New-TimeSpan -Start (Get-Date) -End $StartDate).Days | |
Write-Host "Days To Summit: $days!!" -ForegroundColor Blue | |
} | |
function Remove-RemoteGitBranch { | |
[cmdletbinding()] | |
param( | |
[Parameter(Mandatory = $true, Position = 0)] | |
[String] | |
$Branch | |
) | |
process { | |
if ($PSCmdlet.ShouldContinue("$Branch","DELETE remote branch")) { | |
$gitArgs = @('push' | |
'origin' | |
'--delete' | |
$Branch) | |
git @gitArgs | |
} | |
} | |
} | |
function Set-CFToken { | |
[cmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[SecureString] | |
$ApiToken | |
) | |
process { | |
$hash = @{ | |
CFToken = $ApiToken | |
} | |
return $hash | |
} | |
} | |
function Shock-Employee { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[String] | |
$Name | |
) | |
end { | |
Write-Host "Employee: $Name has been SHOCKED with 220 volts of pure unadulterated pain!!" -ForegroundColor Yellow | |
} | |
} | |
Invoke-Expression (& starship init powershell) | |
Write-Host "Heads up! Daily dad joke incoming!" -ForegroundColor Green | |
Write-Host (Get-DadJoke) -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment