-
Notifications
You must be signed in to change notification settings - Fork 26
/
profile.Jack.template
151 lines (124 loc) · 3.5 KB
/
profile.Jack.template
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
[cmdletBinding()]
Param(
# What name would you prefer the drive to be mapped under.
[string]$Store = "ps"
, # Store Root Path
[string]$StoreRoot = (Join-Path $env:HOMEDRIVE 'ps')
# Verbose output with ". $profile.currentUserAllHosts -Verbose" in a session to view extra information
)
$Verbose = $VerbosePreference
$git = $false
if(Get-Command "git" -ErrorAction SilentlyContinue){
$git = $true
}
# ---------- Create the store drive ----------
$v = measure-command {
try
{
Get-PSDrive $Store -ErrorAction stop
}
catch [System.Exception]
{
Write-Verbose "adding the store: $Store"
$Drive = @{
Root = $StoreRoot
Description = "Powershell script and module store"
Name = $Store
PSProvider = "FileSystem"
}
New-PSDrive @Drive
}
catch
{
Write-Verbose 'No Fault'
}
}
Write-Verbose "$('{0:N6}' -f $v.TotalSeconds) seconds - Detecting store drive"
# ---------- Add store to module path ----------
$v = measure-command {
Write-Verbose "path Before:"
$env:PSModulePath.split(';') | % {Write-Verbose " $PSItem"}
# Check to see if the above added drive is in the module path. If not, add it.
if($env:PSModulePath.Contains("$Store`:"))
{
Write-Verbose "Store exists"
} else {
Write-Verbose "Store not found"
$env:PSModulePath = $env:PSModulePath.Insert(0, "$Store`:\;")
Write-Verbose "path after:"
$env:PSModulePath.split(';') | % {Write-Verbose " $PSItem"}
}
}
Write-Verbose "$($v.TotalSeconds) seconds - add store to path"
$v = measure-command {
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadline
}
}
Write-Verbose "$($v.TotalSeconds) seconds - import PSReadline"
# Set up a simple prompt, adding the git prompt parts inside git repos
function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE
if($git){
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
}
Write-Host($pwd.Path) -nonewline -ForegroundColor Green
if($git){
Write-VcsStatus
}
$global:LASTEXITCODE = $realLASTEXITCODE
[System.Environment]::NewLine + "$env:USERNAME $ "
}
function swap-python {
if($env:path -match 'Python27'){
$env:Path = $env:path.replace('Python27', 'Python34')
} else {
$env:Path = $env:path.replace('Python34', 'Python27')
}
}
function get-list(){
Param(
[switch]$Directory
)
get-childitem @args | format-wide -autosize
}
function new-directory{
new-item -type directory -name $args[0]
Set-Location $args[0]
}
function git-bash{
[string]$string = "$env:ProgramFiles\git\bin\sh.exe --login"
Invoke-Expression $string
}
function touch{
Param(
[Parameter(Mandatory=$true)]
[string]$name
)
if(-not (test-path $name)){
new-item -type file $name -force
} else {
Write-Warning "$name exists"
}
}
function Backup-Profile {
$profile = @{
Path = $profile.CurrentUserAllHosts
Destination = "$Store`:\profile.Jack.template"
Force = $true
}
Copy-Item @profile
}
Set-Alias subl (Join-Path $HOME "Sublime Text 3\sublime_text.exe")
Set-Alias sh git-bash
Set-Alias lsa get-list
Set-Alias new new-directory
Set-Alias g git
$HOMEPATH = Get-PSDrive -Name $HOME.Trim(':\') | select DisplayRoot
if($git){
Enable-GitColors
}
Set-Location "$HOME\src"
lsa -Directory