Skip to content

Instantly share code, notes, and snippets.

@SBajonczak
Last active September 13, 2021 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SBajonczak/2759e387958e042d0f6db139b1178128 to your computer and use it in GitHub Desktop.
Save SBajonczak/2759e387958e042d0f6db139b1178128 to your computer and use it in GitHub Desktop.
Custom PowerShell Profile that contains OmyPosh and some custom git aliasses
if (Get-Module -ListAvailable -Name oh-my-posh) {
}
else{
Install-Module oh-my-posh -Scope CurrentUser -AllowPrerelease
}
if (Get-Module -ListAvailable -Name posh-git) {
}
else{
Install-Module posh-git -Scope CurrentUser -Force
}
# Ensure that Get-ChildItemColor is loaded
Import-Module Get-ChildItemColor
# Set l and ls alias to use the new Get-ChildItemColor cmdlets
Set-Alias l Get-ChildItemColor -Option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -Option AllScope
# Helper function to change directory to my development workspace
# Change c:\ws to your usual workspace and everytime you type
# in cws from PowerShell it will take you directly there.
function cws { Set-Location e:\sourcen }
# Helper function to set location to the User Profile directory
function cuserprofile { Set-Location ~ }
Set-Alias ~ cuserprofile -Option AllScope
function Get-MasterBranch{
$Greped= git remote show origin | findstr -I -N "HEAD"
return $Greped.split(":")[2].Trim()
}
# Git Aliasses
function Do-Sonar {
$branch = (Get-Item .).Name
dotnet sonarscanner begin /k:$branch /d:sonar.exclusions="**/wwwroot/**, **/obj/**, **/bin/**, **/node_modules/** **/src/tailwind.output.css"
dotnet build
dotnet sonarscanner end
}
function Remove-ObsoleteBranches
{
$branchName=Get-MasterBranch
& git checkout $branchName
& git remote update origin --prune
& git branch -vv | Select-String -Pattern ": gone]" | % { $_.toString().Trim().Split(" ")[0]} | % {git branch -d $_}
}
function Get-GitMaster {
$branchName=Get-MasterBranch
& git checkout $branchName
& git pull -r
}
function Set-GitCommit{
& git add .
& gitmoji.cmd -c
}
function Get-GitMergeMaster {
$branchName=Get-MasterBranch
# Get current Branch
$branch = git rev-parse --abbrev-ref HEAD
# Checkout master and fetch all elements
& git checkout $branchName
& git pull
# Switch to working branch
& git checkout $branch
# merge changes from master
& git merge $branchName
}
Set-Alias gim Get-GitMaster -Option AllScope
Set-Alias gimm Get-GitMergeMaster -Option AllScope
Set-Alias gic Set-GitCommit -Option AllScope
Set-Alias gitprune Remove-ObsoleteBranches -Option AllScope
Set-Alias eso Do-Sonar -Option AllScope
# Helper function to show Unicode character
function U
{
param
(
[int] $Code
)
if ((0 -le $Code) -and ($Code -le 0xFFFF))
{
return [char] $Code
}
if ((0x10000 -le $Code) -and ($Code -le 0x10FFFF))
{
return [char]::ConvertFromUtf32($Code)
}
throw "Invalid character code $Code"
}
# Ensure posh-git is loaded
Import-Module -Name posh-git
# Ensure oh-my-posh is loaded
Import-Module -Name oh-my-posh
# Default the prompt to agnoster oh-my-posh theme
# Set-Theme agnoster
Set-PoshPrompt -Theme slim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment