Created
February 13, 2022 00:53
-
-
Save Seekatar/a59919f719900b24cd6802c4cc6b6118 to your computer and use it in GitHub Desktop.
PowerShell $Profile file for Window/Mac
This file contains 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
Import-Module ZLocation | |
Import-Module posh-git | |
Import-Module posh-git | |
if ($PSVersionTable.PSVersion.Major -lt 6) { | |
Import-Module Jump.Location | |
} | |
# Set up a simple prompt, adding the git prompt parts inside git repos | |
function global:prompt { | |
$realLASTEXITCODE = $LASTEXITCODE | |
Write-Host($pwd.ProviderPath) -nonewline | |
Write-VcsStatus | |
$global:LASTEXITCODE = $realLASTEXITCODE | |
return "> " | |
} | |
# =========================================================== | |
# =Basic commands | |
# =========================================================== | |
# turn off annoying beep on backspace | |
Set-PSReadlineOption -BellStyle None | |
Set-StrictMode -Version Latest | |
function .. { Set-Location .. } | |
function ... { Set-Location ..\.. } | |
function .... { Set-Location ..\..\.. } | |
function ..... { Set-Location ..\..\..\.. } | |
# run a script block with wrapped output, like help, see hep below | |
function Run-Wrapped { | |
param( | |
[Parameter(Mandatory = $true)] | |
[ScriptBlock] $sb | |
) | |
if ( $Host -and $Host.UI -and $Host.UI.RawUI ) { | |
$rawUI = $Host.UI.RawUI | |
$oldSize = $rawUI.BufferSize | |
$typeName = $oldSize.GetType( ).FullName | |
$newSize = New-Object $typeName ($Host.UI.RawUI.WindowSize.Width, $oldSize.Height) | |
$rawUI.BufferSize = $newSize | |
& $sb | |
$rawUI.BufferSize = $oldSize | |
} | |
} | |
function nested { | |
if ($PSVersionTable.PSVersion.Major -ge 6) { | |
$me = Get-Process | Where-Object Id -eq $pid | |
$parent = $me.parent | |
return $parent -and ($parent.ProcessName -eq 'powershell' -or $parent.ProcessName -eq 'pwsh') | |
} | |
else { | |
$me = Get-WmiObject -Query "select * from Win32_Process where Handle=$pid" | |
$parent = Get-Process -Id $me.ParentProcessId | |
return $parent.ProcessName -eq 'powershell' | |
} | |
} | |
function t { if ( $args.Length -gt 0 ) { (Get-Host).UI.RawUI.WindowTitle = $args[0] } } | |
function fg { if ( $args.Length -gt 0 ) { (Get-Host).UI.RawUI.ForegroundColor = $args[0] } } | |
function fgt { t $args; fg $args } | |
# =========================================================== | |
# =Shortcuts to installed Apps | |
# =========================================================== | |
function tail { if ( $args.Length -gt 0 ) { Get-Content $args[0] -Wait } } | |
if ($IsWindows) { | |
function vcvarsall { | |
param( | |
[ValidateSet(2015, 2017, 2019)] | |
$Version = 2019 | |
) | |
#Set environment variables for Visual Studio Command Prompt | |
if ($Version -eq 2015) { | |
Push-Location "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools" | |
} | |
elseif ($Version -eq 2017) { | |
Push-Location "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools" | |
} | |
elseif ($Version -eq 2019) { | |
Push-Location "C:\Program Files (x86)\Microsoft Visual Studio\2019\*\Common7\Tools" | |
} | |
cmd /c "VsDevCmd.bat&set" | | |
ForEach-Object { | |
if ($_ -match "=") { | |
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])" | |
} | |
} | |
Pop-Location | |
write-host "`nVisual Studio $version Command Prompt variables set." -ForegroundColor Yellow | |
} | |
vcvarsall | |
set-alias bc "${env:ProgramFiles}\Beyond Compare 4\BComp.exe" | |
set-alias n "$env:windir\notepad" | |
set-alias e explorer | |
function doc { Set-Location "$env:USERPROFILE\Documents" } | |
function bin { Set-Location "$env:USERPROFILE\Documents\bin" } | |
} | |
elseif ($IsMacOS) { | |
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete | |
Set-PSReadLineOption -BellStyle None -EditMode Windows | |
set-alias e open | |
function n { open -a TextEdit @args } | |
set-alias code '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code' | |
set-alias bc '~/Applications/Beyond Compare.app/Contents/MacOS/bcomp' | |
} | |
function __kill( [string] $name ) { | |
$prev = $ErrorActionPreference | |
$ErrorActionPreference = 'SilentlyContinue' | |
$count = @(Get-Process -name $name).Count | |
if ( $count -gt 0 ) { | |
Stop-Process -name $name | |
"Stopped $count $name processes" | |
} | |
else { | |
"No processes named $name running" | |
} | |
$ErrorActionPreference = $prev | |
} | |
function g { fgt Green; Clear-Host; } | |
function b { fg Cyan; t Blue; Clear-Host } | |
function y { fgt Yellow; Clear-Host } | |
$oldPrompt = $function:prompt | |
function prompt { | |
if ( nested ) { | |
$x = (& $oldPrompt) -replace '>', '>>' | |
"Nested $x" | |
} | |
else { | |
& $oldPrompt | |
} | |
} | |
# Chocolatey profile | |
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | |
if (Test-Path($ChocolateyProfile)) { | |
Import-Module "$ChocolateyProfile" | |
} | |
# Default for running dotnet core as Development | |
$env:ASPNETCORE_ENVIRONMENT = "Development" | |
if ( Test-Path ~/CompanySpecific.ps1) { | |
"Loading ~/CompanySpecific.ps1" | |
. ~/CompanySpecific.ps1 | |
} else { | |
"~/CompanySpecific.ps1 not found. Nothing to do." | |
} | |
Set-Alias k kubectl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment