-
Notifications
You must be signed in to change notification settings - Fork 4
/
profile.ps1
150 lines (121 loc) · 3.03 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
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
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
function Test-InPath($fileName){
$found = $false
Find-InPath $fileName | %{$found = $true}
return $found
}
function Find-InPath($fileName){
$env:PATH.Split(';') | ?{!([System.String]::IsNullOrEmpty($_))} | %{
if(Test-Path $_){
ls $_ | ?{ $_.Name -like $fileName }
}
}
}
# Run posh-git init script
pushd
cd posh-git
# Load posh-git module from current directory
Import-Module .\posh-git
Enable-GitColors
popd
# Run posh-hg init script
pushd
cd posh-hg
# Load posh-svn module from current directory
Import-Module .\posh-hg
popd
# Run posh-svn init script
pushd
cd posh-svn
# Load posh-svn module from current directory
Import-Module .\posh-svn
popd
. .\configurePrompt.ps1
# Configure ssh-agent so git doesn't require a password on every push
if(Test-InPath ssh-agent.*){
. .\ssh-agent-utils.ps1
}else{
Write-Error "ssh-agent cannot be found in your PATH, please add it"
}
$clrDir = [System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
$clrDir = split-path $clrDir
$latestClrDir = ls $clrDir | ?{$_.PSIsContainer} | select -last 1
$clrDir = join-path $clrDir $latestClrDir
$env:path = "$($env:path);$clrDir"
$env:EDITOR = "notepad"
# Define variables
if(!(Test-Path .\environment.ps1)){
Write-Error "Environment configfile cannot be found - please edit & continue"
copy environment.example.ps1 environment.ps1
notepad .\environment.ps1
}
. .\environment.ps1
if($dev -eq $null -or !(Test-Path $dev)){
Write-Error "Dev directory cannot be found or is not defined: $dev"
}
# Define aliases
function elevate-process{
$file, [string]$arguments = $args;
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;
[System.Diagnostics.Process]::Start($psi) >> $null
}
set-alias sudo elevate-process
function Get-Git-Status{
git status
}
set-alias gs Get-Git-Status
function Set-Location-Dev($folder){
Push-Location
if($folder -ne ""){
cd "$dev\$folder"
return
}
cd $dev
}
set-alias dev Set-Location-Dev
function Set-Location-Profile{
Push-Location
cd ~\Documents\WindowsPowerShell
}
set-alias profile Set-Location-Profile
function Start-Explorer{
if(!$args) { explorer . }
else { explorer $args }
}
Set-Alias e Start-Explorer
function Start-Notepad{
notepad $args
}
set-alias n Start-Notepad
function Start-VisualStudio{
param([string]$projFile = "")
if($projFile -eq ""){
ls *.sln | select -first 1 | %{
$projFile = $_
}
}
if(($projFile -eq "") -and (Test-Path src)){
ls src\*.sln | select -first 1 | %{
$projFile = $_
}
}
if($projFile -eq ""){
echo "No project file found"
return
}
echo "Starting visual studio with $projFile"
. $projFile
}
set-alias vs Start-VisualStudio
function Set-Hosts{
sudo notepad "$($env:SystemRoot)\system32\drivers\etc\hosts"
}
set-alias hosts Set-Hosts
function Kill-All{
param([string]$name)
get-process | ?{$_.ProcessName -eq $name -or $_.Id -eq $name} | %{kill $_.Id}
}
Pop-Location