Skip to content

Commit af4fdf7

Browse files
committed
Update Profile, Rename Scripts
1 parent 0707371 commit af4fdf7

6 files changed

+172
-94
lines changed

gitutils.ps1 LibGitUtils.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Git functions
22
# Mark Embling (http://www.markembling.info/)
3+
4+
# Add git to our path
5+
append-path ("C:\Program Files (x86)\Git\cmd")
36

47
# Is the current directory a git repository/working copy?
58
function isCurrentDirectoryGitRepository {

hgutils.ps1 LibHgUtils.ps1

File renamed without changes.

LibVcVars.ps1

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function Get-Batchfile ($file) {
2+
$cmd = "`"$file`" & set"
3+
cmd /c $cmd | Foreach-Object {
4+
$p, $v = $_.split('=')
5+
Set-Item -path env:$p -value $v
6+
}
7+
}
8+
9+
function VsVars32($version = "10.0")
10+
{
11+
if (Test-Path "HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7")
12+
{
13+
$vcdirkey = Get-ItemProperty "HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7"
14+
}
15+
else
16+
{
17+
$vcdirkey = Get-ItemProperty "HKLM:SOFTWARE\Microsoft\VisualStudio\SxS\VC7"
18+
}
19+
$vcdir = Get-Member -Name "$version" -InputObject $vcdirkey
20+
$vcdir = $vcdir.Definition.Split('=')[1]
21+
$BatchFile = [System.IO.Path]::Combine($vcdir, "bin\vcvars32.bat")
22+
Get-Batchfile $BatchFile
23+
$global:WindowTitlePrefix = ("VS " + $version + " - ")
24+
#Set-ConsoleIcon ($env:userprofile + "\utils\resources\vspowershell.ico")
25+
}
26+
27+
28+
#Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
29+
30+
# DotSource the Console Icon Stuff
31+
#. ./Set-ConsoleIcon.ps1
32+
33+
#Pop-Location

Microsoft.PowerShell_profile.ps1

+14-76
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
########################################################
2-
#
2+
# Chris Pattersons Powershell Profile
33
########################################################
44
# Load any custom Powershell Snapins that we want
55
function LoadSnapin($name)
@@ -10,25 +10,19 @@ function LoadSnapin($name)
1010
Add-PSSnapin $name
1111
}
1212
}
13+
1314

1415
#####################################################
1516
# Various helper globals
1617
if (-not $global:home) { $global:home = (resolve-path ~) }
1718

1819
$dl = "~\Downloads";
19-
$dev = "C:\Development";
2020
$programs = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]"ProgramFiles");
2121
$scripts = (split-path $profile); # I keep my personal .PS1 files in the same folder as my $profile
2222
$documents = [System.Environment]::GetFolderPath("Personal")
2323
$framework = Join-Path $Env:windir "Microsoft.NET\Framework"
2424
$framework = Join-Path $framework ([Reflection.Assembly]::GetExecutingAssembly().ImageRuntimeVersion)
2525

26-
#####################################################
27-
# Helper scripts we will want
28-
. (resolve-path $scripts\gitutils.ps1)
29-
. (resolve-path $scripts\svnutils.ps1)
30-
. (resolve-path $scripts\hgutils.ps1)
31-
3226
########################################################
3327
# Helper Functions
3428
function ff ([string] $glob) { get-childitem -recurse -filter $glob }
@@ -42,23 +36,29 @@ function strip-extension ([string] $filename) { [system.io.path]::getfilenamewit
4236
function cd.. { cd .. }
4337
function lsf { get-childitem | ? { $_.PSIsContainer -eq $false } }
4438
function lsd { get-childitem | ? { $_.PSIsContainer -eq $true } }
45-
function ie { & 'C:\program files\Internet Explorer\iexplore.exe' $args }
46-
function firefox { & "C:\Program Files\Mozilla Firefox\firefox.exe" $args }
47-
function google { ie "http://www.google.com/search?q=$args" }
48-
function gitbash { & cmd.exe /c $env:userprofile + "\utils\git\bin\sh.exe" -login -i }
39+
function ie { & 'C:\Program Files (x86)\Internet Explorer\iexplore.exe' $args }
40+
function firefox { & "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" $args }
41+
function bing { ie "http://www.bing.com/search?q=$args" }
4942
function prepend-path { $oldPath = get-content Env:\Path; $newPath = $args + ";" + $oldPath; set-content Env:\Path $newPath; }
5043
function append-path { $oldPath = get-content Env:\Path; $newPath = $oldPath + ";" + $args; set-content Env:\Path $newPath; }
5144

5245
########################################################
5346
# Environmental stuff I like...
47+
#####################################################
48+
# Helper scripts we will want
49+
50+
New-PSDrive -Name Scripts -PSProvider FileSystem -Root $scripts
51+
Get-ChildItem scripts:\Lib*.ps1 | % {
52+
. $_
53+
write-host "Loading library file:`t$($_.name)"
54+
}
5455

5556
# Customize the path for PS shells
5657
append-path (split-path $profile) # I put my scripts in the same dir as my profile script
5758
append-path ($env:userprofile + "\utils\bin")
5859
append-path ($env:userprofile + "\utils\sysinternals")
59-
append-path 'C:\Program Files (x86)\GnuWin32\bin'
6060

61-
# Tell UNIX utilities (particulary svn.exe) to use VIM for its editor
61+
# Tell UNIX utilities (particulary svn.exe) to use Notepad2 for its editor
6262
set-content Env:\VISUAL 'notepad2.exe';
6363

6464
# Aliases
@@ -121,13 +121,6 @@ function elevate-process
121121
[System.Diagnostics.Process]::Start($psi);
122122
}
123123

124-
function gvim {
125-
if ($args.Count -gt 0) {
126-
& gvim.exe --remote-tab-silent "${args}"
127-
} else {
128-
& gvim.exe
129-
}
130-
}
131124

132125
filter Format-Bytes {
133126
$units = 'B ', 'KiB', 'MiB', 'GiB', 'TiB';
@@ -249,65 +242,10 @@ function prompt {
249242
Write-Host(']') -nonewline -foregroundcolor Yellow
250243
}
251244

252-
if (Test-SvnWorkingDirectory) {
253-
$info = get-SvnInfo
254-
$status = get-SvnStatus
255-
256-
Write-Host ' svn:[' -nonewline -foregroundColor Yellow
257-
Write-Host('+' + $status.added) -nonewline -foregroundcolor Yellow
258-
Write-Host(' ~' + $status.modified) -nonewline -foregroundcolor Yellow
259-
Write-Host(' -' + $status.deleted) -nonewline -foregroundcolor Yellow
260-
261-
if ($status.untracked -gt 0) {
262-
Write-Host(' !') -nonewline -foregroundcolor Red
263-
}
264-
265-
Write-Host(']') -nonewline -foregroundcolor Yellow
266-
267-
}
268-
269245
return "> "
270246
}
271247

272-
function old_prompt
273-
{
274-
275-
$nextId = (get-history -count 1).Id + 1;
276-
$promptText = "[" + $nextId + "]";
277-
278-
$wi = [System.Security.Principal.WindowsIdentity]::GetCurrent();
279-
$wp = new-object 'System.Security.Principal.WindowsPrincipal' $wi;
280248

281-
if ( $wp.IsInRole("Administrators") -eq 1 )
282-
{
283-
$color = "Red";
284-
$title = "**ADMIN** - " + (get-location).Path;
285-
}
286-
else
287-
{
288-
$color = "Green";
289-
$title = (get-location).Path;
290-
}
291-
292-
if (test-path .git) {
293-
$promptText = $promptText + " (git)"
294-
}
295-
296-
if (test-path .svn) {
297-
$promptText = $promptText + " (svn)"
298-
}
299-
300-
if (test-path env:RazzleToolPath) {
301-
$title = $title + " [Branch: `$/$env:_BuildBranchPrefix$env:_BuildBranch]"
302-
}
303-
304-
$promptText = $promptText + " »"
305-
306-
write-host $promptText -NoNewLine -ForegroundColor $color
307-
$host.UI.RawUI.WindowTitle = $title;
308-
309-
return " "
310-
}
311249

312250
########################################################
313251
# Custom 'cd' command to maintain directory history

Set-ConsoleIcon.ps1

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
##############################################################################
2+
## Script: Set-ConsoleIcon.ps1
3+
## By: Aaron Lerch, tiny mods by Hanselman
4+
## Website: www.aaronlerch.com/blog
5+
## Set the icon of the current console window to the specified icon
6+
## Dot-Source first, like . .\set-consoleicon.ps1
7+
## Usage: Set-ConsoleIcon [string]
8+
## PS:1 > Set-ConsoleIcon "C:\Icons\special_powershell_icon.ico"
9+
##############################################################################
10+
11+
$WM_SETICON = 0x80
12+
$ICON_SMALL = 0
13+
14+
function Set-ConsoleIcon
15+
{
16+
param(
17+
[string] $iconFile
18+
)
19+
20+
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | out-null
21+
$iconFile
22+
# Verify the file exists
23+
if ([System.IO.File]::Exists($iconFile) -eq $TRUE)
24+
{
25+
$icon = new-object System.Drawing.Icon($iconFile)
26+
27+
if ($icon -ne $null)
28+
{
29+
$consoleHandle = GetConsoleWindow
30+
SendMessage $consoleHandle $WM_SETICON $ICON_SMALL $icon.Handle
31+
}
32+
}
33+
else
34+
{
35+
Write-Host "Icon file not found"
36+
}
37+
}
38+
39+
40+
## Invoke a Win32 P/Invoke call.
41+
## From: Lee Holmes
42+
## http://www.leeholmes.com/blog/GetTheOwnerOfAProcessInPowerShellPInvokeAndRefOutParameters.aspx
43+
function Invoke-Win32([string] $dllName, [Type] $returnType,
44+
[string] $methodName, [Type[]] $parameterTypes, [Object[]] $parameters)
45+
{
46+
## Begin to build the dynamic assembly
47+
$domain = [AppDomain]::CurrentDomain
48+
$name = New-Object Reflection.AssemblyName 'PInvokeAssembly'
49+
$assembly = $domain.DefineDynamicAssembly($name, 'Run')
50+
$module = $assembly.DefineDynamicModule('PInvokeModule')
51+
$type = $module.DefineType('PInvokeType', "Public,BeforeFieldInit")
52+
53+
## Go through all of the parameters passed to us. As we do this,
54+
## we clone the user's inputs into another array that we will use for
55+
## the P/Invoke call.
56+
$inputParameters = @()
57+
$refParameters = @()
58+
59+
for($counter = 1; $counter -le $parameterTypes.Length; $counter++)
60+
{
61+
## If an item is a PSReference, then the user
62+
## wants an [out] parameter.
63+
if($parameterTypes[$counter - 1] -eq [Ref])
64+
{
65+
## Remember which parameters are used for [Out] parameters
66+
$refParameters += $counter
67+
68+
## On the cloned array, we replace the PSReference type with the
69+
## .Net reference type that represents the value of the PSReference,
70+
## and the value with the value held by the PSReference.
71+
$parameterTypes[$counter - 1] =
72+
$parameters[$counter - 1].Value.GetType().MakeByRefType()
73+
$inputParameters += $parameters[$counter - 1].Value
74+
}
75+
else
76+
{
77+
## Otherwise, just add their actual parameter to the
78+
## input array.
79+
$inputParameters += $parameters[$counter - 1]
80+
}
81+
}
82+
83+
## Define the actual P/Invoke method, adding the [Out]
84+
## attribute for any parameters that were originally [Ref]
85+
## parameters.
86+
$method = $type.DefineMethod($methodName, 'Public,HideBySig,Static,PinvokeImpl',
87+
$returnType, $parameterTypes)
88+
foreach($refParameter in $refParameters)
89+
{
90+
$method.DefineParameter($refParameter, "Out", $null)
91+
}
92+
93+
## Apply the P/Invoke constructor
94+
$ctor = [Runtime.InteropServices.DllImportAttribute].GetConstructor([string])
95+
$attr = New-Object Reflection.Emit.CustomAttributeBuilder $ctor, $dllName
96+
$method.SetCustomAttribute($attr)
97+
98+
## Create the temporary type, and invoke the method.
99+
$realType = $type.CreateType()
100+
$realType.InvokeMember($methodName, 'Public,Static,InvokeMethod', $null, $null,
101+
$inputParameters)
102+
103+
## Finally, go through all of the reference parameters, and update the
104+
## values of the PSReference objects that the user passed in.
105+
foreach($refParameter in $refParameters)
106+
{
107+
$parameters[$refParameter - 1].Value = $inputParameters[$refParameter - 1]
108+
}
109+
}
110+
111+
function SendMessage([IntPtr] $hWnd, [Int32] $message, [Int32] $wParam, [Int32] $lParam)
112+
{
113+
$parameterTypes = [IntPtr], [Int32], [Int32], [Int32]
114+
$parameters = $hWnd, $message, $wParam, $lParam
115+
116+
Invoke-Win32 "user32.dll" ([Int32]) "SendMessage" $parameterTypes $parameters
117+
}
118+
119+
function GetConsoleWindow()
120+
{
121+
Invoke-Win32 "kernel32" ([IntPtr]) "GetConsoleWindow"
122+
}

vcvars.ps1

-18
This file was deleted.

0 commit comments

Comments
 (0)