-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
531 lines (416 loc) · 16.6 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
531 lines (416 loc) · 16.6 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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
Set-PSReadLineOption -BellStyle None -EditMode Vi
Set-PSReadLineKeyHandler -Chord ctrl+w -Function BackwardDeleteWord
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -PredictionSource None
# from https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/SamplePSReadLineProfile.ps1
# The built-in word movement uses character delimiters, but token based word
# movement is also very useful - these are the bindings you'd use if you
# prefer the token based movements bound to the normal emacs word movement
# key bindings.
Set-PSReadLineKeyHandler -Key Alt+d -Function ShellKillWord
Set-PSReadLineKeyHandler -Key Alt+Backspace -Function ShellBackwardKillWord
Set-PSReadLineKeyHandler -Key Alt+b -Function ShellBackwardWord
Set-PSReadLineKeyHandler -Key Alt+f -Function ShellForwardWord
Set-PSReadLineKeyHandler -Key Alt+B -Function SelectShellBackwardWord
Set-PSReadLineKeyHandler -Key Alt+F -Function SelectShellForwardWord
# Sometimes you enter a command but realize you forgot to do something else first.
# This binding will let you save that command in the history so you can recall it,
# but it doesn't actually execute. It also clears the line with RevertLine so the
# undo stack is reset - though redo will still reconstruct the command line.
Set-PSReadLineKeyHandler -Key Alt+w `
-BriefDescription SaveInHistory `
-LongDescription "Save current line in history but do not execute" `
-ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($line)
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
}
# Insert text from the clipboard as a here string
Set-PSReadLineKeyHandler -Key Ctrl+Alt+v `
-BriefDescription PasteAsHereString `
-LongDescription "Paste the clipboard text as a here string" `
-ScriptBlock {
param($key, $arg)
Add-Type -Assembly PresentationCore
if ([System.Windows.Clipboard]::ContainsText()) {
# Get clipboard text - remove trailing spaces, convert \r\n to \n, and remove the final \n.
$text = ([System.Windows.Clipboard]::GetText() -replace "\p{Zs}*`r?`n", "`n").TrimEnd()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("@'`n$text`n'@")
}
else {
[Microsoft.PowerShell.PSConsoleReadLine]::Ding()
}
}
function Edit-CommandInNvim {
param([System.ConsoleKeyInfo] $key)
# Get the current command line text
$text = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$text, [ref]$null)
# Create a temporary file with the command
$tempFile = [System.IO.Path]::GetTempFileName()
$tempFile = [System.IO.Path]::ChangeExtension($tempFile, "ps1")
try {
# Write the current command to the temp file
Set-Content -Path $tempFile -Value $text -Encoding UTF8
# Start nvim in a new process and wait for it to complete
$process = Start-Process -FilePath "nvim" -ArgumentList $tempFile -Wait -PassThru
if ($process.ExitCode -eq 0) {
# Read the modified content
$newContent = Get-Content -Path $tempFile -Raw
# If content was modified, update the command line
if ($newContent) {
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($newContent.TrimEnd())
}
}
}
finally {
if (Test-Path $tempFile) { Remove-Item -Path $tempFile -Force }
}
}
Set-PSReadLineKeyHandler -Chord 'v' -ScriptBlock ${function:Edit-CommandInNvim} -ViMode Command
Get-Content "C:\Users\sraghuvanshi\src\EXPLOR\app\.env" | ForEach-Object {
$name, $value = $_.Split('=')
if ($name -and $value -and ($name -match '^SEC_.*' -or $name -match '^AZURE_.*$' -or $name -match '^OPENAI_.*$' -or $name -match '^SNOWFLAKE_.*$' -or $name -match '^GEMINI_.*$' -or $name -match '^OAUTH_.*$')) {
[Environment]::SetEnvironmentVariable($name.Trim(), $value.Trim(), "Process")
}
}
$ENV:STARSHIP_CONFIG = "$HOME\.starship"
$ENV:RIPGREP_CONFIG_PATH = "C:\Users\sraghuvanshi\src\dotfiles\.config\.ripgreprc"
$env:GIT_DIFF_OPTS="-u7"
# [Environment]::SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "C:\Users\sraghuvanshi\langgraph.json", "User")
function vim {
if ((Test-Path Env:\TERM_PROGRAM) -and ("vscode" -eq (Get-Item -Path Env:\TERM_PROGRAM).Value)) {
if (-not ($args.Count -eq 0)) {
code $args
}
}
else {
nvim $args
}
}
function vi { vim $args }
function :e { vim $args }
function :E { vim $args }
function :q { exit }
function :Q { exit }
function exi { exit }
function upgrade { explorer https://explor.faralloncapital.com/upgrade }
function upgrad { upgrade }
function upgra { upgrade }
function upgr { upgrade }
function upg { upgrade }
function uptime { explorer https://explor.faralloncapital.com/uptime }
function uptim { uptime }
function upti { uptime }
function upt { uptime }
# function y { if (-not ($args.Count -eq 0)) { yarn $args } else { yarn } }
function yd { yarn dev }
function yts { if (-not ($args.Count -eq 0)) { yarn ts $args } else { yarn ts } }
function ybeo { yarn build-extension-only }
function ybno { yarn build-native-only }
function e { cd ~/src/explor/app }
function e2 { cd ~/src/2explor/app }
function e3 { cd ~/src/3explor/app }
function a_wsl { wsl -d Arch --cd ~/applets }
function a { cd ~/src/applets }
function w { wsl -d Arch --cd ~ }
function deft { cd ~/src/trades_table_pipeline }
function exp { cd ~/src/experiments }
# Git aliases
function g { git $args }
function it { git $args }
function gi { git $args }
function gpul { git pull $args }
function gpull { git pull $args }
function gpush { git push $args }
function gpf { git push --force $args }
function gpuo { git push -u origin "$(git branch --show-current)" }
if (Test-Path Alias:gp) {
Remove-Alias -Name gp -Force
}
function gp {
trap { "Error found. $_" }
git update-index --refresh;
git diff-index --quiet HEAD --;
$need_to_stash = -not ( $? )
if ( $need_to_stash ) {
git stash;
}
git pull;
git push $args;
if ( $need_to_stash ) {
git stash pop;
}
}
if (Test-Path Alias:gc) {
Remove-Alias -Name gc -Force
}
function gc {
trap { "Error found. $_" }
if ($args -contains '--') {
git checkout $args
return
}
git update-index --refresh;
git diff-index --quiet HEAD --;
$need_to_stash = -not ( $? )
if ( $need_to_stash ) {
git stash;
}
git checkout $args
if ( $need_to_stash ) {
git stash pop;
}
}
# git branch search
function gcbrs {
git branch `
--no-color `
--sort=-committerdate `
--format='%(refname:short)' |
fzf --header 'git checkout' |
ForEach-Object { gc $_ }
}
function gcbs { gcbrs }
function gco { gcbrs }
function gcos { gcbrs }
function gcprs {
gh pr list `
--search "sort:updated-desc" `
--json "number,title,headRefName,updatedAt" `
--template '{{range .}}{{tablerow (printf "#%v" .number) .title .headRefName (timeago .updatedAt)}}{{end}}' |
fzf --header 'Checkout PR' |
ForEach-Object { ($_ -split '\s+')[0] } |
ForEach-Object { ($_ -split '#')[1] } |
ForEach-Object { gh pr checkout $_ }
}
function gcprs_me {
gh pr list `
--search "sort:updated-desc" `
--author "@me" `
--json "number,title,headRefName,updatedAt" `
--template '{{range .}}{{tablerow (printf "#%v" .number) .title .headRefName (timeago .updatedAt)}}{{end}}' |
fzf --header 'Checkout PR' |
ForEach-Object { ($_ -split '\s+')[0] } |
ForEach-Object { ($_ -split '#')[1] } |
ForEach-Object { gh pr checkout $_ }
}
function ghprs { gcprs }
function ghprs_me { gcprs_me }
function gcprsme { gcprs_me }
function ghprsme { gcprs_me }
function gcb { git checkout -b $args }
function gcp { git cherry-pick $args }
function gr { git rebase $args }
function gri { git rebase -i $args }
function grc { git rebase --continue }
function gd { git diff -w $args }
function gdiw { git diff $args }
function d { git diff -w $args }
function gds { git diff --staged -w $args }
function gdsiw { git diff --staged $args }
function ga { git add $args }
function gap { git add -p $args }
function ga. { git add . $args }
if (Test-Path Alias:gcm) {
Remove-Alias -Name gcm -Force
}
function gcm { git commit -m $args }
function gstat { git status $args }
function gca { git commit --amend $args }
function gcam { git commit --amend $args }
function gs { git stash $args }
function gssp { git stash show -p $args }
function gsd { git stash drop $args }
function gsp { git show -p $args }
function gf { git fetch $args }
function gpush { git push $args }
function aigcm { aigcm_azure_openai $args }
function gcmai { aigcm $args }
# immortalizing an absolutely unhinged email @bijection got
function hi_guillermo {
git commit -m @"
Hi Guillermo,
It's called a mail merge.
It seems that there could be something wrong with your cerebrum.
Someone who needs a job is attempting to find someone who has available work. Upon noticing this pattern you attempted to murder the job seeker so that you can later eat them as food.
If you analyze the strange trajectory of emotions that you entertained leading up to writing your e-mail, during writing the e-mail, and after writing the e-mail, in very fine detail, you'll realize that you were attempting to fool any law enforcement who later reads your e-mail into thinking that you didn't want to eat me.
When in fact that is exactly what you want.
Best,
Brian
"@
}
function ghrv { gh repo view -w }
function cd.. { cd .. }
function .. { cd .. }
function ... { cd ../.. }
function .... { cd ../../.. }
# function ll { Get-ChildItem -Force $args }
function ll { eza $args }
function p3 { python3 $args }
function py3 { python3 $args }
function open { explorer $args }
# function claude { wsl claude $args }
# function ccusage { wsl npx ccusage@latest $args }
function fun_claude { claude --dangerously-skip-permissions --disallowedTools 'Bash(git push:*)' $args }
function func { fun_claude $args }
Set-Alias -Name "less" -Value "${env:ProgramFiles}\Git\usr\bin\less.exe"
if (-not (Test-Path Alias:which)) {
New-Alias which get-command
}
Import-Module posh-git
if (Test-Path Alias:gcb) {
Remove-Alias -Name gcb -Force
}
Invoke-Expression (&starship init powershell)
#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module
Import-Module -Name Microsoft.WinGet.CommandNotFound
#f45873b3-b655-43a6-b217-97c00aa0db58
$env:AZURE_API_BASE = 'openai-explor-eus2-prod.openai.azure.com'
$env:AZURE_API_VERSION = '2024-12-01-preview'
$env:AZURE_API_KEY = $env:AZURE_OPENAI_KEY_EUS2_EXPLOR
function gcm_trivial {
# Hardcoded Azure OpenAI API details
$hostname = $env:AZURE_API_BASE
$path = '/openai/deployments/gpt-4o/chat/completions?api-version=2024-12-01-preview'
$apiKey = $env:AZURE_API_KEY
if ([string]::IsNullOrWhiteSpace($apiKey)) {
Write-Host "Azure OpenAI API key is not set. Please set the environment variable AZURE_API_KEY."
return
}
$headers = @{
"Content-Type" = "application/json"
"api-key" = $apiKey
}
$body = @{
"messages" = @(
@{
"role" = "system"
"content" = @"
Please write a funnily grandiose commit message for a commit that does not actually do anything meaningful. Only respond with the commit message; do not add any explanatory prefix or suffix.
"@
}
)
"max_tokens" = 2000
} | ConvertTo-Json
$uri = "https://$hostname$path"
echo $uri
$response = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $body
$commitMessage = $response.choices[0].message.content.Trim()
# Create a temporary file with the commit message
$tempFile = [System.IO.Path]::GetTempFileName()
Set-Content -Path $tempFile -Value $commitMessage
# Call git commit with the prepared message
git commit -e -F $tempFile
# Clean up the temporary file
Remove-Item -Path $tempFile
}
function aigcm_azure_openai {
# Get the git diff
$diff = git diff --staged -W -U200
# Check if there are any changes
if ([string]::IsNullOrWhiteSpace($diff)) {
Write-Host "No changes to commit."
return
}
# Hardcoded Azure OpenAI API details
$hostname = 'openai-explor-eus-prod.openai.azure.com'
$path = '/openai/deployments/gpt-4o/chat/completions?api-version=2024-04-01-preview'
$apiKey = $env:AZURE_OPENAI_KEY_EUS2_EXPLOR
if ([string]::IsNullOrWhiteSpace($apiKey)) {
Write-Host "Azure OpenAI API key is not set. Please set the environment variable AZURE_OPENAI_KEY_EUS_EXPLOR."
return
}
# Prepare the API request
$headers = @{
"Content-Type" = "application/json"
"api-key" = $apiKey
}
$body = @{
"messages" = @(
@{
"role" = "system"
"content" = @"
You are tasked with writing a commit message based on the output of a `git diff` command. This is an
important skill for maintaining clear and informative version control history. Your goal is to
create a concise commit message that accurately represents the changes made in the code but elides
minor details.
Here is the output of the `git diff` command:
$diff
To write an effective commit message, follow these steps:
1. Carefully analyze the git diff output. Pay attention to:
- Files that have been modified, added, or deleted
- The nature of the changes (e.g., bug fixes, new features, refactoring)
- Any patterns or themes in the changes
- Note that lines that start with a + are additions, and lines that start
with a - are deletions. Other lines were already present in the file and
were not changed. Your task is to write a commit message only for the changes
present in this commit; DO NOT describe pre-existing code.
2. Summarize the main purpose of the changes in a single, concise sentence. This will be the first
line of your commit message. It should:
- Not be too long (ideally under 100 characters)
- Use the imperative mood (e.g., "Fix bug" not "Fixed bug" or "Fixes bug")
- Clearly convey the primary impact of the changes
3. ONLY IF NECESSARY, provide additional details after two newlines. These details should:
- Explain the reasoning behind the changes
- Highlight any important side effects or implications
- Be formatted as bullet points for clarity
4. Avoid including obvious or redundant information, such as "I updated file X" or listing every
single file changed. Minor changes should not be detailed in the commit message unless they are the
only changes.
Remember, a good commit message should allow someone to understand the essence of the changes
without having to look at the code.
Respond with only your commit message. Ensure that there are two newlines between the summary line
and any additional details. For example:
Implement user authentication
- Add login and registration forms
- Set up JWT token generation and validation
- Create protected routes for authenticated users
"@
}
)
"max_tokens" = 2000
} | ConvertTo-Json
# Make the API call
$uri = "https://$hostname$path"
$response = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $body
# Extract the commit message
$commitMessage = $response.choices[0].message.content.Trim()
# Create a temporary file with the commit message
$tempFile = [System.IO.Path]::GetTempFileName()
Set-Content -Path $tempFile -Value $commitMessage
# Call git commit with the prepared message
git commit -e -F $tempFile
# Clean up the temporary file
Remove-Item -Path $tempFile
}
function aider { uvx --python 3.12 --from aider-chat@latest aider --vim --watch-files --model azure/gpt-4o --weak-model azure/gpt-4o --editor-model azure/gpt-4o --show-model-warnings $args }
function pbcopy {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true)]
[string[]]$InputObject
)
begin {
$text = @()
}
process {
$text += $InputObject
}
end {
$text -join "`n" | Set-Clipboard
}
}
$env:MCFLY_LIGHT = "TRUE"
$env:MCFLY_KEY_SCHEME = "vim"
$env:MCFLY_FUZZY = 2
$env:MCFLY_RESULTS = 50
$env:MCFLY_PROMPT = ">"
Invoke-Expression -Command $(mcfly init powershell | out-string)