-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
199 lines (161 loc) · 4.56 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
199 lines (161 loc) · 4.56 KB
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
Import-Module "$home\.config\posh-git\src\posh-git.psd1"
if ($IsWindows) {
$env:CMakeNuGetPackagePath = "D:\dev\NugetPackages"
} else {
$env:CMakeNuGetPackagePath = "$HOME/.nuget"
}
$env:GIT_SSH = "C:\WINDOWS\System32\OpenSSH\ssh.exe"
$env:NEXUS_ROOT = "C:\ProgramData\nexus"
#
# I don't need the full version-fu for PowerShell in WindowTitle, and I don't
# care about 64-bit, either. In a tabbed console, WindowTitle real estate is
# precious, so abbreviate the WindowTitle suffix to "PS m.n (PID)"
#
$GitPromptSettings.WindowTitle = {param($GitStatus, [bool]$IsAdmin) "$(if ($IsAdmin) {'Admin: '})$(if ($GitStatus) {"$($GitStatus.RepoName) [$($GitStatus.Branch)]"} else {Get-PromptPath}) ~ PS $($PSVersionTable.PSVersion.Major.ToString()).$($PSVersionTable.PSVersion.Minor.ToString()) ($PID)"}
Set-PSReadLineOption -EditMode Vi
function adminsh {
Start-Process -Verb 'runas' -FilePath (Get-Process -Id $PID).Path
}
Function basename {
[CmdletBinding()]
Param(
[String] $Path
)
$p = Get-Item $Path
Return $p.BaseName
}
Function df {
[CmdletBinding()]
Param(
[Switch] $h = $false,
[String] $Path = $pwd
)
$p = Get-Item $Path
Write-Output $p.PSDrive
}
Function dirname {
[CmdletBinding()]
Param(
[String] $Path
)
$p = Get-Item $Path
Return $p.PSParentPath.Split('::')[1]
}
#
# Invoke a "remote" PSSession so that if your terminal window dies, the stuff
# running in the background does not die. This is not as good as screen or
# tmux, but it's *something*. This alias creates the session. You can just use
# Enter-PSSession -Name with the name you gave it to reconnect to it.
#
Function durable {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True, Position=0)]
[String] $Name
)
Enter-PSSession -EnableNetworkAccess -Name $Name
}
Function gctag {
git -c user.email="cbehanna@microsoft.com" `
-c user.name="Chris BeHanna" `
tag
}
Function gfpo { git fetch --filter=blob:none origin --prune }
Function glf {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[String] $remote = "origin",
[Parameter(Mandatory=$True)]
[String] $branch = "main",
[String] $C = "."
)
git -C $C lfs fetch $remote $branch
}
Function grom { git rebase origin/main }
Function grup {
[CmdletBinding()]
Param(
[String] $C = "."
)
git -C $C remote update --prune
}
Function gsuir { git submodule update --init --recursive --filter=blob:none }
New-Alias -Name mvim -Value gvim
New-Alias -Name vs2022 -Value "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.exe"
New-Alias -Name vs2022debug -Value "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VSJITDebugger.exe"
New-Alias -Name which -Value "Get-Command"
#
# Unix-like "time" command
#
#$thisDir = $(Get-Item $profile).DirectoryName
#$time = Join-Path -Path $thisDir -ChildPath "time.ps1"
#. $time
if ($PSVersionTable.PSVersion.Major -ge 7 -and $PSVersionTable.OS.Contains("Windows")) {
Remove-Alias rm
Function rm {
Param(
[Switch]
$rf = $False,
[Parameter(ValueFromRemainingArguments)]
$Remaining
)
if ($rf -Eq $True) {
Remove-Item -Recurse -Force @Remaining
}
else {
Remove-Item @Remaining
}
}
}
#
# For working around colorization bug when passing
# git ls-remote | sls foo
#
Filter slsne {
[CmdletBinding()]
Param(
[String]
$Pattern,
[Parameter(ValueFromPipeline=$true)]
$PipelineInput
)
Begin {}
Process {
foreach($i in $PipelineInput) {
Write-Output [String]$i | Select-String -NoEmphasis -Pattern $Pattern
}
}
End {}
}
#
# WIP
#
Function wc {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline)]
[String] $str = ""
)
# Need to add a sum in here somewhere
Process {
$_ | Measure-Object -line -word -character
}
}
Set-Alias -Name vscode -Value "C:\Program Files\Microsoft VS Code\Code.exe"
#
# Example--useless when posh-git controls the window title.
#
Function xtitle {
Param(
[Parameter(Mandatory = $True, Position = 0)]
[string]
$Title
)
$Host.UI.RawUI.WindowTitle = $Title
}
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}