forked from drmohundro/PowerShellEnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerShell.ps1
73 lines (54 loc) · 2.36 KB
/
PowerShell.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
$NTIdentity = ([Security.Principal.WindowsIdentity]::GetCurrent())
$NTPrincipal = (new-object Security.Principal.WindowsPrincipal $NTIdentity)
$IsAdmin = ($NTPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
$global:shortenPathLength = 3
if(-not (test-path $ProfileDir/Modules)) {
mkdir $ProfileDir/Modules
}
New-PSDrive -Name Modules -PSProvider FileSystem -root $ProfileDir/Modules | Out-Null
$promptCalls = new-object System.Collections.ArrayList
function prompt {
$chost = [ConsoleColor]::Green
$cdelim = [ConsoleColor]::DarkCyan
$cloc = [ConsoleColor]::Cyan
write-host ' '
write-host ([Environment]::MachineName) -nonewline -foregroundcolor $chost
write-host ' {' -nonewline -foregroundcolor $cdelim
write-host (shorten-path (pwd).Path) -nonewline -foregroundcolor $cloc
write-host '} ' -nonewline -foregroundcolor $cdelim
$promptCalls | foreach { $_.Invoke() }
write-host "»" -nonewline -foregroundcolor $cloc
' '
$host.UI.RawUI.ForegroundColor = [ConsoleColor]::White
}
function shorten-path([string] $path = $pwd) {
$loc = $path.Replace($HOME, '~')
# remove prefix for UNC paths
$loc = $loc -replace '^[^:]+::', ''
# make path shorter like tabs in Vim,
# handle paths starting with \\ and . correctly
return ($loc -replace "\\(\.?)([^\\]{$shortenPathLength})[^\\]*(?=\\)",'\$1$2')
}
function Add-CallToPrompt([scriptblock] $call) {
[void]$promptCalls.Add($call)
}
function Add-ToPath {
$args | foreach {
# the double foreach's are to handle calls like 'add-topath @(path1, path2) path3
$_ | foreach { $env:Path += ";$(Resolve-Path $_)" }
}
}
Import-Module Pscx -DisableNameChecking -arg "$(Split-Path $profile -parent)\Pscx.UserPreferences.ps1"
# override the PSCX cmdlets with the default cmdlet
Set-Alias Select-Xml Microsoft.PowerShell.Utility\Select-Xml
Push-Location $ProfileDir
# Bring in env-specific functionality (i.e. work-specific dev stuff, etc.)
If (Test-Path ./EnvSpecificProfile.ps1) { . ./EnvSpecificProfile.ps1 }
# Bring in prompt and other UI niceties
. ./EyeCandy.ps1
Update-TypeData ./TypeData/System.Type.ps1xml
Update-TypeData ./TypeData/System.Diagnostics.Process.ps1xml
. ./lib/aliases.ps1
. ./lib/utils.ps1
Pop-Location
Load-VcVars