Created
September 4, 2018 15:06
-
-
Save RazmikDev/46d73d10a7578ab1eb8406bc94713a35 to your computer and use it in GitHub Desktop.
PowerShell profile for ReSharper/Rider developer
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
# ===================================================================================================================== | |
# Power Plan Management | |
# --------------------------------------------------------------------------------------------------------------------- | |
$powerPlans = powercfg -l | |
$highPerformancePowerPlan = $powerPlans | ForEach-Object { if ($_.contains("High performance")) { | |
$_.split()[3] | |
} | |
} | |
$balancedPowerPlan = $powerPlans | ForEach-Object { if ($_.contains("Balanced")) { | |
$_.split()[3] | |
} | |
} | |
$powerSaverPowerPlan = $powerPlans | ForEach-Object { if ($_.contains("Power saver")) { | |
$_.split()[3] | |
} | |
} | |
$currentPowerPlan = $(powercfg -getactivescheme).split()[3] | |
function Get-Plan { | |
$currentPowerPlanId = $(powercfg -getactivescheme).split()[3] | |
switch ($currentPowerPlanId) { | |
$highPerformancePowerPlan { | |
return "HighPerformance" | |
} | |
$balancedPowerPlan { | |
return "Balanced" | |
} | |
$powerSaverPowerPlan { | |
return "PowerSaver" | |
} | |
} | |
} | |
function Set-Plan { | |
param | |
( | |
[Parameter(Mandatory = $False)][ValidateSet("PowerSaver", "Balanced", "HighPerformance")][string] $Plan | |
) | |
PROCESS { | |
switch ($Plan) { | |
"PowerSaver" { | |
$powerPlan = $powerSaverPowerPlan | |
} | |
"Balanced" { | |
$powerPlan = $balancedPowerPlan | |
} | |
"HighPerformance" { | |
$powerPlan = $highPerformancePowerPlan | |
} | |
} | |
if ([string]::IsNullOrEmpty($powerPlan)) { | |
return | |
} | |
try { | |
powercfg -setactive $powerPlan | |
$Global:currentPowerPlan = $powerPlan | |
Write-Host ("Power plan is set to '" + $Plan + "'") -ForegroundColor Cyan | |
} | |
catch { | |
Write-Error "Failed to set power plan" | |
} | |
} | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# Build Tools | |
# --------------------------------------------------------------------------------------------------------------------- | |
$msbuild12 = "C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" | |
$msbuild14 = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" | |
$msbuild15 = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" | |
function Get-Solutions { | |
$solutions = Get-ChildItem "*sln" | |
$solutionsOfReSharper = $solutions | Where-Object {[string]$_.Name -like "*Generated*" } | |
if ($solutionsOfReSharper.Length -eq 0) { | |
return $solutions; | |
} | |
else { | |
if (Test-Path $solutionsOfReSharper) { | |
return $solutionsOfReSharper | |
} | |
} | |
} | |
function Get-Solution { | |
return Get-Solutions | Select-Object -First 1 | |
} | |
function Start-Build() { | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory = $True, ValueFromPipeline = $True)][string] $Solution, | |
[int]$MaxCpuCount = 4 | |
) | |
PROCESS { | |
$currentPlan = Get-Plan | |
Set-Plan -Plan HighPerformance | |
& $msbuild $Solution /maxcpucount:$MaxCpuCount /ds /v:m | |
Set-Plan -Plan $currentPlan | |
} | |
} | |
Set-Alias build Start-Build | |
Set-Alias solution Get-Solution | |
Set-Alias solutions Get-Solutions | |
if (Test-Path $msbuild15) { | |
$msbuild = $msbuild15 | |
} | |
if (Test-Path $msbuild14) { | |
$msbuild = $msbuild14 | |
} | |
elseif (Test-Path $msbuild12) { | |
$msbuild = $msbuild12 | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# Rider Tools | |
# --------------------------------------------------------------------------------------------------------------------- | |
$rider64 = Get-ChildItem ~/AppData/Local/JetBrains/Toolbox/apps/Rider/ch-0/ -Recurse -Filter "*rider64.exe" | Sort-Object LastWriteTime | ForEach-Object { $_.FullName } | Select-Object -Last 1 | |
function Start-Rider { | |
param | |
( | |
[Parameter(Mandatory = $False, ValueFromPipeline = $True)] [string] $Solution, | |
[Parameter(Mandatory = $False)] [switch] $DisableInternalMode = $False | |
) | |
PROCESS { | |
$rider = $rider64 | |
$expresson = "& `"$rider`" `"$Solution`" " | |
Invoke-Expression $expresson | |
} | |
} | |
Set-Alias rider Start-Rider | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# Visual Studio Tools | |
# --------------------------------------------------------------------------------------------------------------------- | |
$devenv12 = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" | |
$devenv14 = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" | |
$devenv15 = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe" | |
if (Test-Path $devenv12) { | |
$devenv = $devenv12 | |
} | |
elseif (Test-Path $devenv14) { | |
$devenv = $devenv14 | |
} | |
elseif (Test-Path $devenv15) { | |
$devenv = $devenv15 | |
} | |
$vs = $devenv | |
function Start-VisualStudio { | |
param | |
( | |
[Parameter(Mandatory = $False)][ValidateSet('12', '14', '15')] [string] $Version, | |
[Parameter(Mandatory = $False, ValueFromPipeline = $True)] [string] $Solution, | |
[Parameter(Mandatory = $False)] [string] $Hive, | |
[Parameter(Mandatory = $False)][ValidateSet('FATAL', 'ERROR', 'WARN', 'INFO', 'VERBOSE', 'TRACE')] [string] $LogLevel, | |
[Parameter(Mandatory = $False)] [switch] $DisableInternalMode = $False | |
) | |
PROCESS { | |
if (-not $DisableInternalMode) { | |
$ReSharperInternalSwitch = "`/ReSharper.Internal" | |
} | |
if (-not [string]::IsNullOrWhiteSpace($LogLevel)) { | |
$ReSharperLogLevelSwitch = "`/ReSharper.LogLevel $LogLevel" | |
} | |
switch ($Version) { | |
"12" { | |
$visualStudio = $devenv12 | |
} | |
"14" { | |
$visualStudio = $devenv14 | |
} | |
"15" { | |
$visualStudio = $devenv15 | |
} | |
default { | |
$visualStudio = $devenv | |
} | |
} | |
if (-not [string]::IsNullOrWhiteSpace($Hive)) { | |
$HiveSwitch = "`/RootSuffix $Hive" | |
} | |
$expresson = "& `"$visualStudio`" `"$Solution`" $HiveSwitch $ReSharperInternalSwitch $ReSharperLogLevelSwitch" | |
Invoke-Expression $expresson | |
} | |
} | |
Set-Alias vs Start-VisualStudio | |
function Add-VisualStudioShortcut { | |
param | |
( | |
[Parameter(Mandatory = $False)][ValidateSet('12', '14', '15')][string] $Version, | |
[Parameter(Mandatory = $False)][string] $TitleSuffix, | |
[Parameter(Mandatory = $False)][string] $Hive | |
) | |
PROCESS { | |
$ReSharperInternalSwitch = "/ReSharper.Internal" | |
switch ($Version) { | |
"12" { | |
$visualStudio = $devenv12 | |
} | |
"14" { | |
$visualStudio = $devenv14 | |
} | |
"15" { | |
$visualStudio = $devenv15 | |
} | |
default { | |
$visualStudio = $devenv | |
} | |
} | |
$ShortcutName = "Visual Studio $Version $TitleSuffix" | |
$Location = Get-Location | |
if (-not [string]::IsNullOrWhiteSpace($Hive)) { | |
$Arguments = "$ReSharperInternalSwitch" | |
} | |
else { | |
$Arguments = "$ReSharperInternalSwitch /RootSoffix $Hive" | |
} | |
$WshShell = New-Object -comObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut("$Location\$ShortcutName.lnk") | |
$Shortcut.TargetPath = $visualStudio | |
$Shortcut.Arguments = $Arguments | |
$Shortcut.Save() | |
} | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# VCS Tools: HG & Git | |
# --------------------------------------------------------------------------------------------------------------------- | |
function Get-Branch { | |
[string]$currentLocation = Get-Location | |
while (-not [string]::IsNullOrWhiteSpace($currentLocation)) { | |
$gitDirectory = Get-ChildItem $currentLocation -Filter ".git" -Hidden | |
if ($gitDirectory.Exists) { | |
$branches = git branch | |
$branches = ($branches -split "\r\n") | |
foreach ($gitBranch in $branches) { | |
if ($gitBranch[0] -eq "*") { | |
return ($gitBranch -as [string]).Substring(2) | |
} | |
} | |
} | |
else { | |
$hgDirectory = Get-ChildItem $currentLocation -Filter ".hg" -Hidden | |
if ($hgDirectory.Exists) { | |
return hg branch | |
} | |
} | |
$currentLocation = $currentLocation | Split-Path -Parent | |
} | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# VCS Tools: Git | |
# --------------------------------------------------------------------------------------------------------------------- | |
function Show-Commits { | |
param | |
( | |
[Parameter(Mandatory = $False)] | |
[int]$Number = 8, | |
[Parameter(Mandatory = $False)] | |
[string]$Author | |
) | |
PROCESS { | |
if ($Author) { | |
git log -n $Number --no-merges --abbrev-commit --date=local --author $Author | |
} | |
else { | |
git log -n $Number --no-merges --abbrev-commit --date=local | |
} | |
} | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# VCS Tools: HG | |
# --------------------------------------------------------------------------------------------------------------------- | |
function Update-Code { | |
param | |
( | |
[string] $Branch, | |
[switch] $Clear | |
) | |
PROCESS { | |
if ($Clear) { | |
$clearSwitch = "-C" | |
} | |
foreach ($directory in Get-ChildItem -Directory) { | |
if (Test-Path (Join-Path $directory "/.hg")) { | |
Set-Location $directory | |
if ([string]::IsNullOrEmpty($Branch)) { | |
$branchToUpdate = Get-Branch | |
} | |
else { | |
$branchToUpdate = $Branch | |
} | |
$result = & hg update $Branch $clearSwitch | |
Write-Host ($directory.Name + " ") -NoNewline -ForegroundColor Green | |
Write-Host ("[" + $branchToUpdate + "]") -NoNewline -ForegroundColor Yellow | |
Write-Host (": ") -NoNewline | |
Write-Output $result | |
Set-Location .. | |
} | |
} | |
} | |
} | |
function Get-Code { | |
PROCESS { | |
foreach ($directory in Get-ChildItem -Directory) { | |
if (Test-Path (Join-Path $directory "/.hg")) { | |
Set-Location $directory | |
$result = & hg pull | |
Write-Host ($directory.Name + ":") -ForegroundColor Green | |
Write-Host $result | |
Write-Host | |
Set-Location .. | |
} | |
} | |
} | |
} | |
function Get-Changes { | |
param | |
( | |
[switch] $Summary | |
) | |
PROCESS { | |
if ($Summary) { | |
$statFlag = "--stat" | |
} | |
foreach ($directory in Get-ChildItem -Directory) { | |
if (Test-Path (Join-Path $directory "/.hg")) { | |
Set-Location $directory | |
$result = & hg diff $statFlag | |
Write-Host ($directory.Name + ":") -ForegroundColor Green | |
Write-Host $result | |
Write-Host | |
Set-Location .. | |
} | |
} | |
} | |
} | |
function Get-Branches { | |
param | |
( | |
[string] $pattern | |
) | |
PROCESS { | |
hg branches | Where-Object {$_ -like $pattern} | |
} | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# Team City service management | |
# ===================================================================================================================== | |
function Start-TeamCity { | |
PROCESS { | |
Start-Service TCBuildAgent | |
Start-Service TeamCity | |
} | |
} | |
function Stop-TeamCity { | |
PROCESS { | |
Stop-Service TCBuildAgent | |
Stop-Service TeamCity | |
} | |
} | |
function Open-TeamCity { | |
PROCESS { | |
Start-Process "http://localhost:99/" | |
} | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# PROMPT | |
# --------------------------------------------------------------------------------------------------------------------- | |
[string]$branch = ""; | |
function Prompt { | |
[string]$currentLocation = Get-Location | |
[string]$currentLocationParent = Split-Path $currentLocation -Parent | |
[string]$currentLocationLeaf = Split-Path $currentLocation -Leaf | |
$global:branch = Get-Branch | |
$branchLenght = 0 | |
Write-Host "PS" -NoNewline | |
if (-not [string]::IsNullOrWhiteSpace($currentLocationParent)) { | |
Write-Host (" " + $currentLocationParent) -NoNewline -ForegroundColor Gray | |
if (-not $currentLocationParent.EndsWith("\")) { | |
Write-Host "\" -NoNewline -ForegroundColor Gray | |
} | |
Write-Host $currentLocationLeaf -NoNewline | |
} | |
else { | |
Write-Host (" " + $currentLocationLeaf) -NoNewline -ForegroundColor Gray | |
} | |
#Write-Host (" " + $currentLocation) -NoNewline -ForegroundColor Gray | |
if (-not [string]::IsNullOrWhiteSpace($branch)) { | |
$branchLenght = $branch.Length | |
Write-Host " [" -NoNewline | |
Write-Host $branch -NoNewline -ForegroundColor Yellow | |
Write-Host "]" -NoNewline | |
} | |
$space = " " | |
$arrows = ">>" | |
if (($currentLocation.Length + $branchLenght) -gt 64) { | |
Write-Host ([System.Environment]::NewLine + $arrows) -NoNewline -ForegroundColor Green | |
return $space | |
#return [System.Environment]::NewLine + "> " | |
} | |
else { | |
Write-Host ($space + $arrows) -NoNewline -ForegroundColor Green | |
return $space | |
#return "> " | |
} | |
} | |
# ===================================================================================================================== | |
# ===================================================================================================================== | |
# Set current location | |
# --------------------------------------------------------------------------------------------------------------------- | |
$repositoriesPath = Get-ChildItem C:\Repositories\Resharper* | Select-Object -First 1 # JetBrains ReSharper specific | |
#Set-Location $repositoriesPath | |
# ===================================================================================================================== | |
Write-Host "POWER SHELL IS IN YOUR HANDS NOW, BUDDY" -ForegroundColor White -BackgroundColor Blue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment