-
Notifications
You must be signed in to change notification settings - Fork 0
/
Microsoft.PowerShell_profile.ps1
137 lines (104 loc) · 4.09 KB
/
Microsoft.PowerShell_profile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
########################################################
# Chris Pattersons Powershell Profile
########################################################
# Load any custom Powershell Snapins that we want
function LoadSnapin($name)
{
if ((Get-PSSnapin $name -registered -erroraction SilentlyContinue ) -and
(-not (Get-PSSnapin $name -ErrorAction SilentlyContinue)) )
{
Add-PSSnapin $name
}
}
#####################################################
# Various helper globals
if (-not $global:home) { $global:home = (resolve-path ~) }
$dl = "~\Downloads";
$programs = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]"ProgramFiles");
$scripts = (split-path $profile); # I keep my personal .PS1 files in the same folder as my $profile
$documents = [System.Environment]::GetFolderPath("Personal")
$framework = Join-Path $Env:windir "Microsoft.NET\Framework"
$framework = Join-Path $framework ([Reflection.Assembly]::GetExecutingAssembly().ImageRuntimeVersion)
########################################################
# Environmental stuff I like...
#####################################################
# Helper scripts we will want
New-PSDrive -Name Scripts -PSProvider FileSystem -Root $scripts
Get-ChildItem scripts:\Lib*.ps1 | % {
. $_
}
# Customize the path for PS shells
append-path (split-path $profile) # I put my scripts in the same dir as my profile script
append-path ("C:\Program Files\7-Zip\")
append-path ("C:\Program Files (x86)\Git\bin")
append-path ("C:\Program Files (x86)\Git\cmd")
append-path ($env:userprofile + "\utils\bin")
append-path ($env:userprofile + "\utils\sysinternals")
# Import Modules
# Import-Module Pscx
Import-Module posh-git
Import-Module posh-hg
Import-Module PowerTab
# Tell UNIX utilities (particulary svn.exe) to use Notepad2 for its editor
set-content Env:\VISUAL 'notepad2.exe';
# Aliases
set-alias wide format-wide;
set-alias sudo elevate-process;
set-alias count measure-object;
set-alias reflector $($env:userprofile + "\utils\Reflector\Reflector.exe");
# Remove ri so the ruby ri works
# if (test-path alias:\ri) { remove-item -force alias:\ri }
# Load my personal types tweaks
# Update-TypeData $scripts\types.ps1xml
# I don't like the default more function, so replace it w/ less.exe
# if (test-path function:\more) { remove-item -force function:\more }
# set-alias more less
# I also don't like the built in man function and use my own script instead
# if (test-path function:\man) { remove-item -force function:\man }
# set-alias man get-help
# Use my custom set-variable2 function instead of straight up set-variable
if (test-path alias:\set) { remove-item -force alias:\set }
set-alias set set-variable2
########################################################
# Prompt
function get-CurrentDirectoryName {
$path = ""
$pathbits = ([string]$pwd).split("\", [System.StringSplitOptions]::RemoveEmptyEntries)
if($pathbits.length -eq 1) {
$path = $pathbits[0] + "\"
} else {
$path = $pathbits[$pathbits.length - 1]
}
$path
}
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
$nextId = (get-history -count 1).Id + 1;
Write-Host "$($nextId): " -noNewLine
# Figure out current directory name
$currentDirectoryName = get-CurrentDirectoryName
# Admin mode prompt?
$wi = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$wp = new-object 'System.Security.Principal.WindowsPrincipal' $wi;
$userLocation = $env:username + '@' + [System.Environment]::MachineName
if ( $wp.IsInRole("Administrators") -eq 1 )
{
$color = "Red";
$title = "**ADMIN** - " + $userLocation + " " + $currentDirectoryName
}
else
{
$color = "Green";
$title = $userLocation + " " + $currentDirectoryName
}
# Window title and main prompt text
$host.UI.RawUi.WindowTitle = $global:WindowTitlePrefix + $title
Write-Host $userLocation -nonewline -foregroundcolor $color
Write-Host (" " + $currentDirectoryName) -nonewline
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
Write-VcsStatus
$LASTEXITCODE = $realLASTEXITCODE
return "> "
}
Enable-GitColors