-
Notifications
You must be signed in to change notification settings - Fork 1
/
Microsoft.PowerShell_profile.ps1
636 lines (547 loc) · 18.2 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
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
Import-Module -Name Terminal-Icons
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
function cd... { Set-Location ..\.. }
function cd.... { Set-Location ..\..\.. }
function md5 { Get-FileHash -Algorithm MD5 $args }
function sha1 { Get-FileHash -Algorithm SHA1 $args }
function sha256 { Get-FileHash -Algorithm SHA256 $args }
function n { notepad $args }
function HKLM: { Set-Location HKLM: }
function HKCU: { Set-Location HKCU: }
function Env: { Set-Location Env: }
if (Test-Path "$env:USERPROFILE\Work Folders") {
New-PSDrive -Name Work -PSProvider FileSystem -Root "$env:USERPROFILE\Work Folders" -Description "Work Folders"
function Work: { Set-Location Work: }}
function prompt {
if ($isAdmin) {
"[" + (Get-Location) + "] # "
} else {
"[" + (Get-Location) + "] $ "
}}
$Host.UI.RawUI.WindowTitle = "PowerShell {0}" -f $PSVersionTable.PSVersion.ToString()
if ($isAdmin) {
$Host.UI.RawUI.WindowTitle += " [ADMIN]"}
Set-Alias -Name su -Value admin
Set-Alias -Name sudo -Value admin
set-alias -name j -value z
Remove-Variable identity
Remove-Variable principal
Function Test-CommandExists {
Param ($command)
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
try { if (Get-Command $command) { RETURN $true } }
Catch { Write-Host "$command does not exist"; RETURN $false }
Finally { $ErrorActionPreference = $oldPreference }}
if (Test-CommandExists nvim) {
$EDITOR='nvim'
} elseif (Test-CommandExists pvim) {
$EDITOR='pvim'
} elseif (Test-CommandExists vim) {
$EDITOR='vim'
} elseif (Test-CommandExists vi) {
$EDITOR='vi'
} elseif (Test-CommandExists code) {
$EDITOR='code'
} elseif (Test-CommandExists notepad) {
$EDITOR='notepad'
} elseif (Test-CommandExists notepad++) {
$EDITOR='notepad++'
} elseif (Test-CommandExists sublime_text) {
$EDITOR='sublime_text'
}
Set-Alias -Name vim -Value $EDITOR
# psreadline & fzf extension tambahan
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'
Set-PsFzfOption -TabExpansion
# # # # #
# script singkat
function ll { Get-ChildItem -Path $pwd -File }
function g { Set-Location $HOME\Documents\Github }
function desktop { Set-Location $HOME\Desktop }
function htdoc { Set-Location c:\xampp\htdocs }
function src { Set-Location 'C:\Program Files\Go\src' }
function home { Set-Location 'C:\' }
function linux { Set-Location '\\wsl$\Ubuntu-20.04\home\r' }
function c {Clear}
function e {explorer .}
function v {code .}
function rprofile {& $profile}
function profile {code $HOME\Documents\\WindowsPowerShell}
# connect server ssh
function serv {
ssh -i C:/Users/R/priv.pem root@47.236.4.238
}
# langsung buka vscode di directory
function vs {
param(
[string]$argument
)
j $argument
v
}
# Untuk Mengurai Penggunaan Ram
function ram {
$exePath = Join-Path -Path $HOME -ChildPath "Documents\GitHub\ps\Scriptadd\RAM.exe"
Start-Process -FilePath $exePath
Start-Sleep -Milliseconds 1000
Stop-Process -Name "ram"
}
# langsung buka explore di directory
function ee {
param(
[string]$argument
)
j $argument
e
}
# list directory
function dirs {
if ($args.Count -gt 0) {
Get-ChildItem -Recurse -Include "$args" | Foreach-Object FullName
} else {
Get-ChildItem -Recurse | Foreach-Object FullName
}}
# ganti ke admin
function admin {
if ($args.Count -gt 0) {
$argList = "& '" + $args + "'"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $argList
} else {
Start-Process "$psHome\powershell.exe" -Verb runAs
}}
# commit file
function gcom {
git add .
git commit -m "$args"
}
# push file
function gup {
git add .
git commit -m "$args"
git push
}
function gupp {
param(
[string]$argument
)
j $argument
# Eksekusi perintah git add .
git add .
# Eksekusi perintah git commit -m "$args"
git commit -m "$args"
# Eksekusi perintah git push
git push
# Tampilkan status git setelah push (opsional)
git status
}
# mengetahui ip publik
function Get-PubIP {
(Invoke-WebRequest http://ifconfig.me/ip ).Content
}
# mengetahui uptime device
function uptime {
Get-WmiObject win32*operatingsystem | Select-Object csname, @{
LABEL = 'LastBootUpTime';
EXPRESSION = { $*.ConverttoDateTime($\_.lastbootuptime) }
}}
# mencari file
function find-file($name) {
Get-ChildItem -recurse -filter "_${name}_" -ErrorAction SilentlyContinue | ForEach-Object {
$place_path = $_.directory
Write-Output "${place*path}\${*}"
}}
# mencari text
function grep($regex, $dir) {
if ( $dir ) {
Get-ChildItem $dir | select-string $regex
return
}
$input | select-string $regex
}
# mengetahu ukuran file
function df {
get-volume
}
# menganti file
function sed($file, $find, $replace) {
(Get-Content $file).replace("$find", $replace) | Set-Content $file
}
# menentukan definisi
function which($name) {
Get-Command $name | Select-Object -ExpandProperty Definition
}
# export env
function export($name, $value) {
set-item -force -path "env:$name" -value $value;
}
# menghentikan proses
function pkill($name) {
Get-Process $name -ErrorAction SilentlyContinue | Stop-Process
}
# menampilkan proses
function pgrep($name) {
Get-Process $name
}
# membuka localhost web ketika ngoding (localhost/$folderName)
function web {
$folderName = Split-Path -Leaf (Get-Location)
$filePath = "C:\xampp\htdocs\$folderName"
$url = "http://localhost/$folderName/"
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
& $chromePath $url
}
# membuka localhost
function local {
$url = "http://localhost/phpmyadmin/"
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
& $chromePath $url
}
# menjalankan xampp
function xampprun {
Set-Location 'C:\xampp'
Start-Process 'apache_start.bat' -WindowStyle Minimized
Start-Process 'mysql_start.bat' -WindowStyle Minimized
}
# menghentikan xampp
function xamppstop {
Set-Location 'C:\xampp'
taskkill /f /im httpd.exe
& '.\mysql\bin\mysqladmin.exe' -u root shutdown
}
# menjalankan mysql
function mysql {
& 'C:\xampp\mysql\bin\mysql.exe' -u root -p
}
# menghentikan linux
function linuxstop {
wsl.exe --terminate ubuntu-20.04
}
# mengecek status linux
function linuxstat {
wsl --list -v
}
function s {
cd ..
}
# # # # #
# menghapus file-file sementara
function remove {
try {
Write-Host "Menghapus file-file sementara temp..." -NoNewLine -ForegroundColor Yellow
Get-ChildItem -Path "C:\Windows\Temp" -Filter *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
Write-Host "Selesai." -ForegroundColor Green
$userTempPath = $env:TEMP
Write-Host "Menghapus file-file sementara dari $userTempPath..." -NoNewLine -ForegroundColor Yellow
Get-ChildItem -Path $userTempPath -Filter *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
Write-Host "Selesai." -ForegroundColor Green
Write-Host "Menghapus file-file Prefetch dari Prefetch..." -NoNewLine -ForegroundColor Yellow
Get-ChildItem -Path "C:\Windows\Prefetch" -Filter *.* | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Host "Selesai." -ForegroundColor Green
Write-Host "Mengosongkan Recycle Bin..." -NoNewLine -ForegroundColor Yellow
Clear-RecycleBin -Force -Confirm:$false -ErrorAction SilentlyContinue
Write-Host "Selesai." -ForegroundColor Green
Write-Host "Menjalankan Disk Cleanup..." -NoNewLine -ForegroundColor Yellow
Start-Process -FilePath "cleanmgr.exe" -ArgumentList "/d C: /VERYLOWDISK" -NoNewWindow
Write-Host "Selesai." -ForegroundColor Green
Write-Host "Semua file-file yang ditargetkan telah dihapus." -ForegroundColor Cyan
}
catch {
Write-Host "Terjadi kesalahan saat menghapus file: $($_.Exception.Message)" -ForegroundColor Red
}
}
# api chatgpt
$script:OpenAI_Key = "key"
function ask
{
param(
[string]$question,
[int]$tokens = 500,
[switch]$return
)
$key = $script:openai_key
$url = "https://api.openai.com/v1/completions"
$body = [pscustomobject]@{
"model" = "text-davinci-003"
"prompt" = "$question"
"temperature" = .2
"max_tokens"=$tokens
"top_p"=1
"n"=1
"frequency_penalty"= 1
"presence_penalty"= 1
}
$header = @{
"Authorization" = "Bearer $key"
"Content-Type" = "application/json"
}
$bodyJSON = ($body | ConvertTo-Json -Compress)
try
{
$res = Invoke-WebRequest -Headers $header -Body $bodyJSON -Uri $url -method post
if ($PSVersionTable.PSVersion.Major -ne 5) {
$output = ($res | convertfrom-json -Depth 3).choices.text.trim()
}else{
$output = ($res | convertfrom-json).choices.text.trim()
}
$formattedOutput = "# " + $question + " " + $output
if ($return)
{
return $formattedOutput
} else
{
write-host $formattedOutput
}
} catch
{
write-error $_.exception
}
}
# membuka github rezapace
function gr {
$url = "https://github.com/rezapace?tab=repositories"
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
& $chromePath $url
}
# generate new repo
function gn {
$url = "https://github.com/new"
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
& $chromePath $url
}
# menampilkan layar hp
function hp {
cd $HOME\Documents\GitHub
.\scrcpy -m720 -b30m
}
# melakukan posting media sosial
function posting {
$urls = @(
"https://github.com/rezapace?tab=repositories",
"https://www.linkedin.com/feed/",
"https://www.instagram.com/rezarh.go/",
"https://www.facebook.com/",
"https://www.threads.net/@rezarh.go",
"https://twitter.com/home"
)
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
foreach ($url in $urls) {
& $chromePath $url
}
}
# membuat file baru
function Nf {
param (
[string]$FileName
)
# Mendapatkan jalur ke direktori saat ini
$CurrentDirectory = Get-Location
# Menggabungkan nama file dengan jalur direktori saat ini
$FilePath = Join-Path $CurrentDirectory $FileName
# Membuat file baru
New-Item -ItemType File -Path $FilePath -Force
# Membuka file dengan Notepad
Start-Process "notepad.exe" -ArgumentList $FilePath
}
# Function untuk mengaktifkan fitur Virtual Machine Platform
function vmstop {
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
}
# Function untuk menonaktifkan fitur Virtual Machine Platform
function vmstart {
dism.exe /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /disable-feature /featurename:VirtualMachinePlatform /all /norestart
Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -NoRestart
}
#Close all Program in Windows 10
function closeall {
Stop-Process -Name "OfficeClickToRun" -Force
Stop-Process -Name "GoogleCrashHandler" -Force
Stop-Process -Name "GoogleCrashHandler64" -Force
Stop-Process -Name "Telegram" -Force
Stop-Process -Name "Code" -Force
Stop-Process -Name "chrome" -Force
Stop-Process -Name "notepad" -Force
Stop-Process -Name "7zFM" -Force
Stop-Process -Name "Discord" -Force
Stop-Process -Name "WINWORD" -Force
Stop-Process -Name "EXCEL" -Force
Stop-Process -Name "POWERPNT" -Force
Stop-Process -Name "Notion" -Force
Stop-Process -Name "vlc" -Force
Stop-Process -Name "xampp-control" -Force
Stop-Process -Name "cmd" -Force
Stop-Process -Name "SearchApp" -Force
Stop-Process -Name "Postman" -Force
Stop-Process -Name "obs64" -Force
Stop-Process -Name "GitHubDesktop" -Force
Stop-Process -Name "wpscenter" -Force
Stop-Process -Name "wpscloudsvr" -Force
Stop-Process -Name "vmware-authd" -Force
Stop-Process -Name "vmnetdhcp" -Force
Stop-Process -Name "vmnat" -Force
Stop-Process -Name "vmware-usbarbitrator64" -Force
Stop-Process -Name "vmware-unity-helper" -Force
Stop-Process -Name "vmware" -Force
Stop-Process -Name "vmware-tray" -Force
Stop-Process -Name "AsusLinkRemote" -Force
Stop-Process -Name "AsusSystemDiagnosis" -Force
Stop-Process -Name "AsusSwitch" -Force
Stop-Process -Name "AsusLinkNear" -Force
Stop-Process -Name "MicrosoftEdgeUpdate" -Force
Stop-Process -Name "TiWorker" -Force
}
function dbgo {
migrate -database "postgres://postgres:mysecretpassword@localhost:5432/Tiketing?sslmode=disable" -path db/migration-golang up
}
# mengubah ke asci
# function touch($file) {
# "" | Out-File $file -Encoding ASCII
# }
# menghubungkan port
# function konek {
# param(
# [Parameter(Mandatory=$true)]
# [string]$ip,
# [int]$listenport = 8000,
# [int]$connectport = 8000
# )
# $listenaddress = $ip.Trim()
# $connectaddress = $($(wsl hostname -I).Trim())
# $cmd = "netsh interface portproxy add v4tov4 listenport=$listenport listenaddress=$listenaddress connectport=$connectport connectaddress=$connectaddress"
# Invoke-Expression $cmd
# }
# menghentikan port
# function stop {
# netsh interface portproxy reset
# }
# mengecek port
# function cek {
# netsh interface portproxy show v4tov4
# }
# menjalankan server laravel
# function cirun {
# php spark serve
# }
# mengcopy file
# function cp {
# $currentDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# $fileName = Read-Host "Enter the file name to copy"
# $sourceFilePath = Join-Path $currentDir $fileName
# if (-not (Test-Path $sourceFilePath)) {
# Write-Host "Error: $fileName not found in $currentDir" -ForegroundColor Red
# return
# }
# $destFileName = Read-Host "Enter the destination file name"
# $destFilePath = Join-Path $currentDir $destFileName
# Copy-Item $sourceFilePath $destFilePath
# if (Test-Path $destFilePath) {
# Write-Host "$fileName copied to $destFilePath" -ForegroundColor Green
# } else {
# Write-Host "Error: $fileName copy to $destFilePath failed" -ForegroundColor Red
# }
# }
# memindahkan file
# function mv { # Get current PowerShell directory
# $currentDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# $fileName = Read-Host "Enter the file name to move"
# $sourceFilePath = Join-Path $currentDir $fileName
# if (-not (Test-Path $sourceFilePath)) {
# Write-Host "Error: $fileName not found in $currentDir" -ForegroundColor Red
# return
# }
# $destFileName = Read-Host "Enter the destination file name"
# $destFilePath = Join-Path $currentDir $destFileName
# Move-Item $sourceFilePath $destFilePath
# Write-Host "$fileName moved to $destFilePath"
# }
# mengedit profile
# function Edit-Profile {
# if ($host.Name -match "ise") {
# $psISE.CurrentPowerShellTab.Files.Add($profile.CurrentUserAllHosts)
# } else {
# notepad $profile.CurrentUserAllHosts
# }}
# unzip file
# function unzip ($file) {
# Write-Output("Extracting", $file, "to", $pwd)
# $fullFile = Get-ChildItem -Path $pwd -Filter .\cove.zip | ForEach-Object { $_.FullName }
# Expand-Archive -Path $fullFile -DestinationPath $pwd
# }
# zip file
# function zip {
# param(
# [Parameter(Mandatory=$true)]
# [string]$name
# )
# $path = (Get-Location).Path
# Compress-Archive -Path "$path\*" -DestinationPath "$path\..\$name.zip"
# }
# menggabungkan pdf
# function gabung {
# $folder = Get-Location
# $pdfs = Get-ChildItem -Path $folder -Filter *.pdf | Select-Object -ExpandProperty FullName
# $output = Join-Path -Path $folder -ChildPath "output.pdf"
# & "C:\Program Files\gs\gs10.00.0\bin\gswin64c.exe" -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dQUIET -sOutputFile="$output" $pdfs
# }
# convert pdf
# function opdf {
# [CmdletBinding()]
# param(
# [Parameter(Mandatory=$true, Position=0)]
# [string]$InputFile,
# [Parameter(Mandatory=$true, Position=1)]
# [string]$OutputFile
# )
# $arguments = @(
# "-sDEVICE=pdfwrite",
# "-dCompatibilityLevel=1.4",
# "-dPDFSETTINGS=/screen",
# "-dNOPAUSE",
# "-dQUIET",
# "-dBATCH",
# "-sOutputFile=$OutputFile",
# $InputFile
# )
# &"C:\Program Files\gs\gs9.54.0\bin\gswin64c.exe" @arguments
# if (Test-Path $OutputFile) {
# return $true
# }
# else {
# return $false
# }}
# convert docx to pdf
# function p2w { # Load Aspose.PDF DLL
# Add-Type -Path "C:\Program Files (x86)\Aspose\Aspose.PDF for .NET\Bin\net4.0\Aspose.PDF.dll"
# $pdfFile = Read-Host "Enter the PDF file location and name (e.g. C:\Folder\a.pdf)"
# $doc = New-Object Aspose.Pdf.Document($pdfFile)
# $saveOptions = New-Object Aspose.Pdf.DocSaveOptions
# $saveOptions.Format = "DocX"
# $outputFolder = Split-Path $pdfFile
# $outputFile = Join-Path $outputFolder "output.docx"
# $doc.Save($outputFile, $saveOptions)
# Write-Host "PDF file converted to DOCX. Output file: $outputFile"
# }
# menjalankan peco
# function Invoke-PecoHistory {
# $command = Get-History | peco | select -expandproperty CommandLine
# if ($command) {
# Invoke-Expression $command
# }
# }
# Set-PSReadLineKeyHandler -Key Ctrl+f -ScriptBlock ${function:Invoke-PecoHistory}
# lokasi profile theme
oh-my-posh init pwsh --config $HOME\Documents\GitHub\powershell-profile\rezapace.theme.omp.json | Invoke-Expression
# menjalankan chocolatey
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}