forked from ilude/WindowsPowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.ps1
119 lines (95 loc) · 2.95 KB
/
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
# Directory where this file is located
$script:pwd = Split-Path $MyInvocation.MyCommand.Path
# $paths = Join-Path $pwd paths.txt
# if(Test-Path $paths) {
# Get-Content $paths | foreach {
# if(Test-Path $_) {
# $env:Path += ";" + $_
# }
# }
# }
$script:powershell_path = "C:\Windows\System32\WindowsPowerShell\v1.0".ToLower()
if((-Not $env:path.ToLower().contains($script:powershell_path)) -And (Test-Path $script:powershell_path)) {
$env:path = "$env:path;$script:powershell_path"
}
$script:rsync_path = Join-Path $pwd 'rsync'
if(Test-Path $script:rsync_path) {
$env:path = "$env:path;$script:rsync_path"
}
# $devkit = "C:\opscode\chefdk\embedded\"
# if(Test-Path $devkit) {
# $env:RI_DEVKIT = "$devkit"
# $env:path = "$devkit\bin;$devkit\mingw\bin;$env:path"
# }
$env:SSL_CERT_FILE = Join-Path $pwd cacert.pem
# set vagrant default provider
# https://www.vagrantup.com/docs/providers/default.html
$env:VAGRANT_DEFAULT_PROVIDER = "hyperv"
###########################
#
# Load all modules
#
###########################
Get-ChildItem $pwd *.psm1 | foreach {
Import-Module $_.VersionInfo.FileName -DisableNameChecking -verbose:$false
}
try {
$script:git_exe = @((which git.exe).Definition)[0]
if($script:git_exe) {
$env:GITDIR = split-path $script:git_exe | split-path
}
}
catch {
Write-Error "Error setting GITDIR! " + Error[0].Exception
}
###########################
#
# Setup prompt
#
###########################
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
$path = $(get-location).Path
$index = $path.LastIndexOf('\') + 1
$userLocation = $path
if($index -lt $path.Length) {
$userLocation = $path.Substring($index, $path.Length - $index)
}
Write-Host($userLocation) -nonewline -foregroundcolor Green
if (Test-GitRepository) {
$branch = Get-GitBranch
Write-Host '[' -nonewline -foregroundcolor Yellow
Write-Host $branch -nonewline -foregroundcolor Cyan
Write-Host ']' -nonewline -foregroundcolor Yellow
$host.UI.RawUi.WindowTitle = "Git:$userLocation - $pwd"
}
elseif ($userLocation -eq $pwd) {
$host.UI.RawUi.WindowTitle = "$pwd"
}
else {
$host.UI.RawUi.WindowTitle = "$userLocation - $pwd"
}
$LASTEXITCODE = $realLASTEXITCODE
return "> "
}
###########################
#
# Setup Tab Expansion
#
###########################
$defaul_tab_expansion = 'Default_Tab_Expansion'
if((Test-Path Function:\TabExpansion) -and !(Test-Path Function:\$defaul_tab_expansion)) {
Rename-Item Function:\TabExpansion $defaul_tab_expansion
}
function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
switch -regex ($lastBlock) {
# Execute git tab completion for all git-related commands
"$(Get-GitAliasPattern) (.*)" { GitTabExpansion $lastBlock }
# Fall back on existing tab expansion
default { & $defaul_tab_expansion $line $lastWord }
}
}
# https://github.com/samneirinck/posh-docker
Import-Module posh-docker
#Check-RemoteRepository $pwd -verbose