-
Notifications
You must be signed in to change notification settings - Fork 0
/
Microsoft.PowerShell_profile.ps1
250 lines (218 loc) · 7.18 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
set-location C:\
$scripts = "C:\nsynk-system\scripts\ps\"
#msbuild
set-alias msbuild C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
# firefox
Set-Alias ff "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
# notepat
Set-Alias edit 'C:\Program Files\Notepad++\notepad++.exe'
#set-alias for graphics magick
Set-Alias im "C:\Program Files\ImageMagick-7.0.5-Q16\magick.exe"
#list directories only
function getdir {get-childitem | ?{$_.psiscontainer}}
set-alias lsd -value getdir
#emacs nowindow
function emacs-nw($file)
{
&((gcm emacs).Source) -nw $file
}
set-alias em emacs-nw
# get-remaining battery time
function getruntime {(Get-WmiObject win32_battery).estimatedruntime}
set-alias grt -value getruntime
#zip
set-alias uzip expand-archive
set-alias zip compress-archive
function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
#ls date sorted
function lsw ($count)
{
if ($count -eq $Null){Get-ChildItem | Sort-Object -property LastWriteTime}
else {gci | sort-object -property LastWriteTime | select-object -last $count}
}
#get 5 most cpu consuming processes
function cpu ($count)
{
if ($count -eq $Null) {get-process | sort-object CPU -desc | format-table CPU,ProcessName}
else {get-process | sort-object CPU -desc | select-object -first $count | format-table CPU,ProcessName}
}
#Alias
Set-Alias touch -Value New-Item
#create vvvv plugin template in current directory
function create-vvvv-template ($name) {
if($name -eq $Null) {
Write-Output "you must specify a name!"
}
else {
Write-Output "Clone Repo - should be changed to donwload a zip"
git clone https://bitbucket.org/ingolfheinsch/vvvv-plugin-template.git
Write-Output "rename folder"
Rename-Item .\vvvv-plugin-template -NewName $name
Write-Output "rename solution & csproj"
$sln = ".sln"
$csproj = ".csproj"
$cs = ".cs"
$soultion = $name+$sln
$project = $name+$csproj
$class = $name+$cs
Rename-Item .\$name\vvvv-plugin-template.sln -NewName $soultion
Rename-Item .\$name\vvvv-plugin-template.csproj -NewName $project
# Rename-Item .\$name\Class1.cs -NewName $class
Set-Location .\$name
Write-Output "install latest paket"
.paket\paket.bootstrapper.exe
Write-Output "run paket install"
.paket\paket.exe init
.paket\paket.exe install
#update build batch
Write-Output "update build batch"
(Get-Content .\build.bat).replace('vvvv-plugin-template.csproj', $project) | Set-Content .\build.bat
}
}
#teleport
set-alias teleport -value tp
$targets = @{}
$targets.Add("hm", $HOME)
$targets.Add("ad", $HOME + "\AppData\Roaming\")
$targets.Add("dl", $HOME + "\Downloads\")
$targets.Add("sys", "c:\nsynk-system\")
$targets.Add("pl", "c:\nsynk-system\vvvv-packs\nodes\plugins\")
$targets.Add("mod", "c:\nsynk-system\vvvv-packs\nodes\modules\")
$targets.Add("vv", "c:\vvvv\")
$targets.Add("scr", "c:\nsynk-system\scripts\")
$targets.Add("cfg", "c:\nsynk-system\scripts\config\")
$targets.Add("tl", "c:\nsynk-system\tools\")
$targets.Add("choc", "c:\programdata\chocolatey\bin\")
#read additional targets from file
$targetfile = $HOME + "\targets.tp"
if (test-path $targetfile)
{
#$filetarget = (get-content $targetfile) | convertfrom-stringdata
#if($filetarget -ne $Null) {$targets += $filetarget}
write-output "Load teleport targets from: " $targetfile
foreach ($tg in (get-content -raw $targetfile))
{
# write-output $tg
$targets += ($tg | convertfrom-stringdata)
}
}
else
{
write-output "no local teleport target file found."
}
#add new targets to file
function addPersistantTarget ($id)
{
if (!(test-path $targetfile)){ touch $targetfile}
$currentTargets = @{}
if ($filetarget -ne $Null){$currentTargets += $filetarget}
$currentTargets.Add($id, $targets.Item($id))
#$currentTargets | export-csv c:\temp\csv.test
foreach($t in $currentTargets)
{
foreach($k in $t.keys){
foreach($v in $t.values){
$entry = ($k + " = " + $v) -join " "
add-content $targetfile $entry
}
}
}
write-output "target added."
}
function tp ($action, $id)
{
if ($action -eq $Null -and $id -eq $Null)
{
Write-Output "Weclome to Teleport!"
Write-Output "Teleport let you create warppoints to your favourite locations."
Write-Output "try: tp help"
break
}
if ($action -eq "help")
{
Write-Output "usage: tp [action] [target]"
Write-Output "actions: -list, add, remove, goto"
break
}
if ($action -eq "add")
{
if($targets.ContainsKey($id)) {
Write-Output "target:$id already exist. add '-o' option to overwrite."
# $targets.Set_Item($id, $PWD)
}
else {
$targets.Add($id, $PWD)
addPersistantTarget($id)
}
break
}
if ($action -eq "remove") {
$targets.Remove($id)
break
}
if ($action -eq "list") {
Write-Output Teleport-Warppoints
$targets
break
}
if ($action -eq "goto")
{
if ($targets.ContainsKey($id)){
set-location $targets.$id
break
}
else {
Write-Output "target not found"
break
}
}
if ($targets.ContainsKey($action)){
set-location $targets.$action
}
else {
Write-Output "target not found"
}
}
## THE PROMPT
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
Write-Host
# Reset color, which can be messed up by Enable-GitColors
# $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
if (Test-Administrator) { # Use different username if elevated
Write-Host "(Elevated) " -NoNewline -ForegroundColor White
}
Write-Host "$ENV:USERNAME@" -NoNewline -ForegroundColor DarkYellow
Write-Host "$ENV:COMPUTERNAME" -NoNewline -ForegroundColor Magenta
if ($s -ne $null) { # color for PSSessions
Write-Host " (`$s: " -NoNewline -ForegroundColor DarkGray
Write-Host "$($s.Name)" -NoNewline -ForegroundColor Yellow
Write-Host ") " -NoNewline -ForegroundColor DarkGray
}
Write-Host " : " -NoNewline -ForegroundColor DarkGray
Write-Host $($(Get-Location) -replace ($env:USERPROFILE).Replace('\','\\'), "~") -NoNewline -ForegroundColor Blue
Write-Host " : " -NoNewline -ForegroundColor DarkGray
# Write-Host (Get-Date -Format G) -NoNewline -ForegroundColor DarkMagenta
# Write-Host " : " -NoNewline -ForegroundColor DarkGray
$global:LASTEXITCODE = $realLASTEXITCODE
Write-VcsStatus
Write-Host ""
return "> "
}
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}