Last active
September 25, 2015 22:47
-
-
Save ScottWeinstein/996881 to your computer and use it in GitHub Desktop.
My Powershell profile
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
locals.ps1 | |
vs2010.ps1 |
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
$JavaHome = "C:\Program Files\Java\jdk1.7.0" | |
$Java = "C:\Java" | |
$ScalaHome = "$Java\scala" | |
$PlayHome = "$Java\play-2.1-RC1" | |
$NODE_HOME = "C:\Program Files\nodejs" | |
$PythonHome = "C:\Python27" | |
$GitHome = "C:\Program Files (x86)\Git\bin" | |
$GitHubSrc = "~\documents\d\GitHub" | |
$poshGitProfile = "$GitHubSrc\posh-git\profile.example.ps1" | |
$ModHome = "~\Documents\WindowsPowerShell\Modules" | |
$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps" | |
$mydir = (gi $MyInvocation.MyCommand.Path).Directory | |
function Test-FileDep($a,$b) | |
{ | |
$bExists = test-path $b | |
$aExists = test-path $a | |
if (-not $aExists) { | |
return $false | |
} | |
$aTs = (Get-Item $a).LastWriteTime | |
return $bExists -and $aTs -le (Get-Item $b).LastWriteTime | |
} | |
function Update-Path($val) | |
{ | |
if (!$ENV:PATH.contains($val)) | |
{ | |
$ENV:PATH += ";$val" | |
} | |
} | |
function Write-Info($name) | |
{ | |
write-host " $name" -ForegroundColor Green -NoNewLine | |
} | |
# | |
# VisualStudio | |
# | |
function Set-VisualStudioEnvVars | |
{ | |
if ($ENV:VSVARSLOADED) { | |
return | |
} | |
$psvsvarFile = "~\Documents\WindowsPowerShell\vs2010.ps1" | |
$VSDir = 'C:\Program Files (x86)\Microsoft Visual Studio 11.0' | |
if (!(test-path $VSDir)) | |
{ | |
write-host "no VS found" | |
return | |
} | |
$depA = -not (Test-FileDep "$VSDir\Common7\Tools\VsDevCmd.bat" $psvsvarFile) | |
$depB = -not (Test-FileDep $MyInvocation.ScriptName $psvsvarFile) | |
if ($depA -or $depB) | |
{ | |
Write-Host -ForegroundColor yellow "regen vsvars" | |
if (Test-path $psvsvarFile ) | |
{ | |
Remove-Item -Force $psvsvarFile | |
} | |
pushd "$VSDir\VC" | |
cmd /c "vcvarsall.bat&set" | | |
foreach { | |
if ($_ -match "=") { | |
$v = $_.split("="); "set-item -force -path 'ENV:\$($v[0])' -value '$($v[1])'" | Out-File -Append -FilePath $psvsvarFile | |
} | |
} | |
popd | |
} | |
Write-Info "VS2010" | |
. $psvsvarFile | |
$ENV:VSVARSLOADED = $true | |
} | |
# | |
# Main | |
# | |
Write-Info "Loading..." | |
Set-VisualStudioEnvVars | |
# | |
# Modules | |
# | |
if (Test-Path $ModHome) | |
{ | |
Write-Info "PSModules" | |
$Env:PSModulePath += ";$ModHome" | |
if (Test-Path $Moddir\Pscx) | |
{ | |
Write-Info "PSCX" | |
Import-Module Pscx | |
} | |
} | |
# | |
# SQL | |
# | |
if (Test-Path $sqlpsreg) | |
{ | |
Write-Info "SQLServer" | |
if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue") | |
{ | |
throw "SQL Server Provider is not installed." | |
} | |
else | |
{ | |
$item = Get-ItemProperty $sqlpsreg | |
$sqlpsPath = [System.IO.Path]::GetDirectoryName($item.Path) | |
} | |
# | |
# Set mandatory variables for the SQL Server rovider | |
# | |
Set-Variable -scope Global -name SqlServerMaximumChildItems -Value 0 | |
Set-Variable -scope Global -name SqlServerConnectionTimeout -Value 30 | |
Set-Variable -scope Global -name SqlServerIncludeSystemObjects -Value $false | |
Set-Variable -scope Global -name SqlServerMaximumTabCompletion -Value 1000 | |
# | |
# Load the snapins, type data, format data | |
# | |
if (!(Get-PSProvider SqlServer -ErrorAction SilentlyContinue)) | |
{ | |
Push-Location | |
cd $sqlpsPath | |
Add-PSSnapin SqlServerCmdletSnapin100 | |
Add-PSSnapin SqlServerProviderSnapin100 | |
Update-TypeData -PrependPath SQLProvider.Types.ps1xml | |
update-FormatData -prependpath SQLProvider.Format.ps1xml | |
Pop-Location | |
} | |
} | |
# | |
# Git | |
# | |
if (Test-Path $GitHome) | |
{ | |
Write-Info "Git" | |
Update-Path $GitHome | |
$ENV:HOME = $Env:HOMEPATH | |
set-Alias g git.exe | |
function Start-GitSession | |
{ | |
$a = & ssh-agent -c | |
($_,$e,$v) = $a[0].split(" ;") | |
Set-Item ENV:\$e $v | |
($_,$e,$v) = $a[1].split(" ;") | |
Set-Item ENV:\$e $v | |
& ssh-add | |
} | |
} | |
## | |
## Path Provider | |
## | |
#if (test-path "$GitHubSrc\PathProvider\PathProvider.ps1") | |
#{ | |
# Write-Host "Loading PathProvider" -ForegroundColor green | |
# . "$GitHubSrc\PathProvider\PathProvider.ps1" | |
#} | |
# | |
# Java | |
# | |
if (test-path $JavaHome) | |
{ | |
Write-Info "Java" | |
$ENV:JAVA_HOME = $JavaHome | |
$ENV:JDK_HOME = $JavaHome | |
set-alias mvn "$Java\maven\bin\mvn.bat" | |
$ENV:M2_HOME = "$Java\maven\" | |
} | |
# | |
# Scala | |
# | |
if (test-path $ScalaHome) | |
{ | |
Write-Info "Scala" | |
$ENV:SCALA_HOME = $ScalaHome | |
$ScalaCP = "$ScalaHome\lib\jline.jar;$ScalaHome\lib\scala-compiler.jar;$ScalaHome\lib\scala-dbc.jar;$ScalaHome\lib\scala-library.jar;$ScalaHome\lib\scala-swing.jar;$ScalaHome\lib\scalap.jar" | |
function sbt | |
{ | |
$useColors = "" | |
$sbtJar = "$ScalaHome\bin\sbt-launch.jar" | |
if (gcm ansicon -ErrorAction silentlycontinue) | |
{ | |
$useColors = "`-Djline.terminal=jline.UnixTerminal" | |
& ansicon java -Xmx512M -jar $sbtJar $useColors $args | |
} | |
else | |
{ | |
& java -Xmx512M -jar $sbtJar $args | |
} | |
} | |
function scala | |
{ | |
& "$JavaHome\bin\java.exe" -Xmx256M -Xms32M `-Dscala.home=$ScalaHome `-Dscala.usejavacp=true -cp $ScalaCP scala.tools.nsc.MainGenericRunner $args | |
} | |
function scalap | |
{ | |
& "$JavaHome\bin\java.exe" -Xmx256M -Xms32M `-Dscala.home=$ScalaHome `-Dscala.usejavacp=true -cp $ScalaCP scala.tools.scalap.Main $args | |
} | |
} | |
# | |
# Node | |
# | |
if (test-path $NODE_HOME) | |
{ | |
Write-Info "Node" | |
$NODE_HOME = (gi $NODE_HOME).FullName | |
$ENV:NODE_HOME = $NODE_HOME | |
Update-Path $NODE_HOME | |
} | |
# | |
# Posh-git | |
# | |
if (Test-Path $poshGitProfile) | |
{ | |
Write-Info "posh-git" | |
. $poshGitProfile | |
# $GitPromptSettings.RepositoriesInWhichToDisableFileStatus = "C:\Users\Scott\Documents\d\education" | |
} | |
# | |
# Python | |
# | |
if (Test-Path $PythonHome) | |
{ | |
Write-Info "Python2.7" | |
Update-Path $PythonHome | |
set-Alias coverage "$PythonHome\Scripts\coverage.exe" | |
} | |
# | |
# Local | |
# | |
if (test-path "~\bin") | |
{ | |
Update-Path (Get-Item ~\bin).FullName | |
} | |
# | |
# Play | |
# | |
if (test-path $PlayHome) | |
{ | |
Write-Info "play" | |
Update-Path $PlayHome | |
} | |
function st | |
{ | |
& 'C:\Program Files\Sublime Text 3\sublime_text.exe' $args | |
} | |
write-host "" | |
if (Test-Path $mydir/locals.ps1) | |
{ | |
Write-Info "Loading local" | |
. $mydir/locals.ps1 | |
} | |
write-host "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment