Skip to content

Instantly share code, notes, and snippets.

@RazmikDev
Last active Nov 29, 2015
Embed
What would you like to do?
PS profile for ReSharper developers (should replace $profile)
# =====================================================================================================================
# Power Plan Management
# ---------------------------------------------------------------------------------------------------------------------
$powerPlans = powercfg -l
$highPerformancePowerPlan = $powerPlans | %{ if ($_.contains("High performance")) { $_.split()[3] }}
$balancedPowerPlan = $powerPlans | %{ if ($_.contains("Balanced")) { $_.split()[3] }}
$powerSaverPowerPlan = $powerPlans | %{ 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"
function Get-Solution
{
$solution = ls "*sln" | Where-Object {[string]$_.Name -like "*Generated*" }
if (Test-Path $solution)
{
return $solution
}
}
function Start-Build()
{
[CmdletBinding()]
param([int]$MaxCpuCount = 4)
PROCESS
{
$solution = Get-Solution
$currentPlan = Get-Plan
Set-Plan -Plan HighPerformance
& $msbuild $solution /maxcpucount:$MaxCpuCount
Set-Plan -Plan $currentPlan
}
}
if (Test-Path $msbuild12)
{
$msbuild = $msbuild12
}
elseif (Test-Path $msbuild14)
{
$msbuild = $msbuild14
}
# =====================================================================================================================
# =====================================================================================================================
# 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"
if (Test-Path $devenv12)
{
$devenv = $devenv12
}
elseif (Test-Path $devenv14)
{
$devenv = $devenv14
}
$vs = $devenv
function Start-VisualStudio
{
param
(
[Parameter(Mandatory = $False)][ValidateSet('12','14')][string] $Version,
[Parameter(Mandatory = $False, ValueFromPipeline = $True)][string] $Solution,
[Parameter(Mandatory = $False)][string] $Hive
)
PROCESS
{
$ReSharperInternalSwitch = "/ReSharper.Internal"
switch ($Version)
{
"12" { $visualStudio = $devenv12 }
"14" { $visualStudio = $devenv14 }
default { $visualStudio = $devenv }
}
if ([string]::IsNullOrWhiteSpace($Hive))
{
& $visualStudio $Solution $ReSharperInternalSwitch
}
else
{
& $visualStudio $Solution /RootSuffix $Hive $ReSharperInternalSwitch
}
}
}
# =====================================================================================================================
# =====================================================================================================================
# VCS Tools: HG & Git
# ---------------------------------------------------------------------------------------------------------------------
function Get-Branch
{
[string]$currentLocation = pwd
while(-not [string]::IsNullOrWhiteSpace($currentLocation))
{
$gitDirectory = ls $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 = ls $currentLocation -Filter ".hg" -Hidden
if ($hgDirectory.Exists)
{
return hg branch
}
}
$currentLocation = $currentLocation | Split-Path -Parent
}
}
# =====================================================================================================================
# =====================================================================================================================
# VCS Tools: HG
# ---------------------------------------------------------------------------------------------------------------------
function Update-Code
{
param
(
[string] $Branch,
[switch] $Clear
)
PROCESS
{
if ($Clear)
{
$clearSwitch = "-C"
}
foreach($directory in ls -Directory)
{
if (Test-Path (Join-Path $directory "/.hg"))
{
cd $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
echo $result
cd ..
}
}
}
}
function Get-Code
{
PROCESS
{
foreach($directory in ls -Directory)
{
if (Test-Path (Join-Path $directory "/.hg"))
{
cd $directory
$result = & hg pull
Write-Host ($directory.Name + ":") -ForegroundColor Green
Write-Host $result
Write-Host
cd ..
}
}
}
}
function Get-Changes
{
param
(
[switch] $Summary
)
PROCESS
{
if ($Summary)
{
$statFlag = "--stat"
}
foreach($directory in ls -Directory)
{
if (Test-Path (Join-Path $directory "/.hg"))
{
cd $directory
$result = & hg diff $statFlag
Write-Host ($directory.Name + ":") -ForegroundColor Green
Write-Host $result
Write-Host
cd ..
}
}
}
}
# =====================================================================================================================
# =====================================================================================================================
# PROMPT
# ---------------------------------------------------------------------------------------------------------------------
[string]$branch = "";
function prompt
{
[string]$currentLocation = pwd
[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
}
if (($currentLocation.Length + $branchLenght) -gt 64)
{
Write-Host ([System.Environment]::NewLine + ">") -NoNewline -ForegroundColor Green
return " "
#return [System.Environment]::NewLine + "> "
}
else
{
Write-Host " >" -NoNewline -ForegroundColor Green
return " "
#return "> "
}
}
# =====================================================================================================================
# =====================================================================================================================
# JetBrains ReSharper specific
# ---------------------------------------------------------------------------------------------------------------------
$repositoriesPath = ls C:\Repositories\ReSharper* | Select-Object -First 1
cd $repositoriesPath
# =====================================================================================================================
Write-Host "POWER SHELL IS IN YOUR HANDS NOW, BUDDY" -ForegroundColor White -BackgroundColor DarkBlue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment