-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_profile.ps1
786 lines (646 loc) · 21.7 KB
/
user_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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
using namespace System.Collections.Generic
# set PowerShell to UTF-8
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
Import-Module posh-git
$omp_config = Join-Path $PSScriptRoot ".\takuya.omp.json"
oh-my-posh --init --shell pwsh --config $omp_config | Invoke-Expression
Import-Module -Name Terminal-Icons
# PSReadLine
Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineOption -BellStyle None
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadLineOption -PredictionSource History
# Fzf
Import-Module PSFzf
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'
# Env
$env:GIT_SSH = "C:\Windows\system32\OpenSSH\ssh.exe"
# Alias
Set-Alias -Name vim -Value nvim
Set-Alias ll ls
Set-Alias grep findstr
Set-Alias tig 'C:\Program Files\Git\usr\bin\tig.exe'
Set-Alias less 'C:\Program Files\Git\usr\bin\less.exe'
Set-Alias .. cd..
Set-Alias vi nvim
# Tools
Set-Alias -Name ex -Value exitFn
Set-Alias -Name flush -Value flushdns
Set-Alias -Name touch -Value touchFn
Set-Alias -Name v -Value nvimFN
Set-Alias -Name c -Value cdFN
Set-Alias -Name dev -Value devFN
Set-Alias -Name e -Value eFN
Set-Alias -Name n -Value nFN
Set-Alias -Name ta -Value tFN
Set-Alias -Name tai -Value taiFN
Set-Alias -Name co -Value coFN
Set-Alias -Name nrd -Value nrdFN
Set-Alias -Name pass -Value passg
Set-Alias -Name p -Value pnpmRunDevFn
Set-Alias -Name miduco -Value miducoFN
Set-Alias -Name ppa -Value ppathFN # copy pwd to clip
Set-Alias -Name palp -Value palFN # print aliases
Set-Alias -Name pal -Value palPS1FN # print aliases
function palfn {
$filepath = "$env:USERPROFILE\.config\powershell\aliasses.txt" # reemplaza con la ruta correcta a tu archivo de aliases
$aliases = get-content $filepath
$aliases | out-host
}
function palPS1fn {
$filepath = "$env:USERPROFILE\.config\powershell\aliasses.ps1"
if (Test-Path $filePath) {
$commands = Get-Content $filePath
foreach ($command in $commands) {
Invoke-Expression $command
}
} else {
Write-Output "El archivo 'aliasses.ps1' no se encontró en la ubicación especificada."
}
}
function pnpmRunDevFn {
pnpm run dev
}
# Utilities
function which ($command) {
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
function nvimFN {
nvim .
}
function flushdns {
ipconfig /flushdns
}
function gcme ($v) {
Write-Output "git commit -m $v`""
git commit -m $v
}
function cdFN ($v = '.') {
cd $v
ls
}
function touchFn ($value) {
new-Item -Name $value
}
function devFn {
npm run dev
}
function exitFN {
cheatmodes
exit
}
function eFN {
explorer .
}
function coFN {
code .
}
function nFN ($p, $n, $i) {
# url, name, ico
npm start
#nativefier $p -n $n -i $i
}
function tFN {
Write-Output '<script src="https://cdn.tailwindcss.com"></script>'
}
function taiFN {
Write-Output "
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [],
theme: {
extend: {},
},
plugins: [],
}
" >> tailwind.config.js
}
function ppathFN {
(pwd | Select-Object -Last 1).Path | clip
Write-Host 'Path copiado satisfactoriamente!'
}
# --------------------------------------------------------------------- @Miduco ---------------------------------------------------------------------
Set-Alias -Name gmidu -Value gmiduco
Set-Alias -Name gF -Value gcmeFeat
Set-Alias -Name gfix -Value gcmeFix
Set-Alias -Name gperf -Value gcmePerf
Set-Alias -Name gref -Value gcmeRef
Set-Alias -Name gdocs -Value gcmeDocs
Set-Alias -Name gtest -Value gcmeTest
Set-Alias -Name gbuild -Value gcmeBuild
function Highlight-Text($text, $color) {
$colors = @{
'Black' = 0
'DarkBlue' = 1
'DarkGreen' = 2
'DarkCyan' = 3
'DarkRed' = 4
'DarkMagenta' = 5
'DarkYellow' = 6
'Gray' = 7
'DarkGray' = 8
'Blue' = 9
'Green' = 10
'Cyan' = 11
'Red' = 12
'Magenta' = 13
'Yellow' = 14
'White' = 15
}
$colorCode = $colors[$color]
if (-not $colorCode) {
Write-Host "Invalid color specified: $color" -ForegroundColor Red
return
}
$escapedColor = [char]27 + "[38;5;${colorCode}m"
$resetColor = [char]27 + "[0m"
$highlightedText = $text -replace "($text)", "${escapedColor}`$1${resetColor}"
Write-Host $highlightedText
}
function Highlight-T($text, $highlight, $color) {
$startIndex = $text.IndexOf($highlight)
$endIndex = $startIndex + $highlight.Length
Write-Host -NoNewline $text.Substring(0, $startIndex)
Write-Host -NoNewline $highlight -ForegroundColor $color
Write-Host $text.Substring($endIndex)
}
function gmiduco {
#Write-Output "gM - para sacar este menú de comandos"
#Write-Host "○ gF 🆕 feat · Add new feature" -ForegroundColor Yellow
#Highlight-Text "○ gF 🆕 feat · Add new feature" "Yellow"
#Write-Output "○ gperf ⚡️perf · Improve performance"
#Write-Output "○ gref 🛠 refactor · Refactor code"
#Write-Output "○ gdocs 📚 docs · Add or update documentation"
#Write-Output "○ gtest 🧪 test · Add or update tests"
#Write-Output "○ gbuild 🏗️ build · Add or update build scripts"
Highlight-Text "gmidu - para sacar este menú de comandos" "DarkGray"
Write-Host "`n`COMANDOS & TIPOS DE COMMIT: `n` " -ForegroundColor Cyan
Highlight-T "gF | 🆕 feat · Add new feature" "gF" "Yellow"
Highlight-T "gfix | 🐛 fixed · Submit a fixed to a bug" "gfix" "Green"
Highlight-T "gperf | ⚡️perf · Improve performance" "gperf" "Blue"
Highlight-T "gref | 🛠 refactor · Refactor code" "gref" "Magenta"
Highlight-T "gdocs | 📚 docs · Add or update documentation" "gdocs" "White"
Highlight-T "gtest | 🧪 test · Add or update tests" "gtest" "DarkRed"
Highlight-T "gbuild | 🏗️ build · Add or update build scripts" "gbuild" "DarkGreen"
Write-Host
}
function gcmeFeat ($v) {
Write-Output "git commit -m `"🆕 feat: $v`""
git commit -m "🆕 feat: $v"
}
function gcmeFix ($v) {
Write-Output "git commit -m `"🐛 fix: $v`""
git commit -m "🐛 fix: $v"
}
function gcmePerf ($v) {
Write-Output "git commit -m `"⚡️perf: $v`""
git commit -m "⚡️perf: $v"
}
function gcmeRef ($v) {
Write-Output "git commit -m `"🛠 refactor: $v`""
git commit -m "🛠 refactor: $v"
}
function gcmeDocs ($v) {
Write-Output "git commit -m `"📚 docs: $v`""
git commit -m "📚 docs: $v"
}
function gcmeTest ($v) {
Write-Output "git commit -m `"🧪 test: $v`""
git commit -m "🧪 test: $v"
}
function gcmeBuild ($v) {
Write-Output "git commit -m `"🏗️ build: $v`""
git commit -m "🏗️ build: $v"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Miduco ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# --------------------------------------------------------------------- @Git ---------------------------------------------------------------------
Set-Alias -Name g -Value git
Set-Alias gs gist
Set-Alias ga. gitaddDot
Set-Alias -Name ga -Value gitaddspread
Set-Alias -Name grsurl -Value grsurlFN
Set-Alias -Name gpof -Value gpofFN
Set-Alias -Name gco -Value gcme
Set-Alias -Name ginit -Value gitInit
Set-Alias -Name gll -Value gitll
Set-Alias -Name gpob -Value gpobFN
Set-Alias -Name gdiff -Value gdiffFN
Set-Alias -Name gcoa -Value gcoaFN
Set-Alias -Name gpush -Value gitPushFn
Set-Alias -Name gllt -Value gitLogHistTakuyaFn
Set-Alias -Name gllf -Value gitLogTakuyaFn
Set-Alias -Name gpusht -Value gitPushTakuyaFn
Set-Alias -Name gpu -Value gitPushTakuyaFnFinal
Set-Alias -Name open -Value gitOPENTakuyaFn
Set-Alias -Name gtestT -Value gtestFn
Set-Alias -Name gCreateBranch -Value gCreateBranchFn
Set-Alias -Name gNewBranch -Value gNewBranchFn
function gNewBranchFn ($branchName) {
if ($branchName) {
git checkout -b $branchName
} else {
Write-Output "Dont missing branchName"
}
}
function gCreateBranchFn ($branchName) {
if ($branchName) {
git switch -c $branchName
} else {
Write-Output "Dont missing branchName"
}
}
function gitLogHistTakuyaFn ($v) {
if($v) {
git log --pretty=format:\"%Cgreen%h %Creset%cd %Cblue[%cn] %Creset%s%C(yellow)%d%C(reset)\" --graph --date=relative --decorate -$v
} else {
git log --pretty=format:\"%Cgreen%h %Creset%cd %Cblue[%cn] %Creset%s%C(yellow)%d%C(reset)\" --graph --date=relative --decorate --all
}
}
function gitLogTakuyaFn ($p) {
if($p) {
git log --graph --name-status --pretty=format:\"%C(red)%h %C(reset)(%cd) %C(green)%an %Creset%s %C(yellow)%d%Creset\" --date=relative --decorate -$p
} else {
git log --graph --name-status --pretty=format:\"%C(red)%h %C(reset)(%cd) %C(green)%an %Creset%s %C(yellow)%d%Creset\" --date=relative
}
}
function gitPushTakuyaFn {
git push origin (git rev-parse --abbrev-ref HEAD)
}
function gitPushTakuyaFnFinal {
git pull origin develop && git push origin (git rev-parse --abbrev-ref HEAD)
}
function gitOPENTakuyaFn {
$remoteUrl = git remote get-url origin
$baseUrl = $remoteUrl -replace "git@(.*):(.*)\.git", "https://`$1/`$2"
$branch = git rev-parse --abbrev-ref HEAD
$url = "$baseUrl"
Start-Process $url
}
function gtestFn {
git log --pretty=format:\"%Cgreen%h %Creset%cd %Cblue[%cn] %Creset%s%C(yellow)%d%C(reset)\" --graph --date=relative --decorate --all | Select-String "commit" | ForEach-Object { $_.ToString().Split()[1] }
}
function gcoaFN ($p) {
git commit --amend $p
}
function gitaddspread {
param (
[Parameter(Mandatory=$true, Position=0, ValueFromRemainingArguments=$true)]
[string[]]$files
)
foreach ($file in $files) {
git add $file
}
git status
gmidu
}
function gitaddDot ($p) {
git add $p
}
function gitll {
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
}
function gpofFN {
git push --set-upstream origin main
}
function gpobFN($p) {
git push --set-upstream origin $p
}
function grsurlFN ($param) {
git remote set-url origin $param
}
function gitPushFn {
git push
}
function gist {
git status
Highlight-Text "--------------------------" "DarkGray"
Highlight-Text "pal - para sacar los alias" "Yellow"
Highlight-Text "--------------------------" "DarkGray"
gmidu
}
function gitInit {
git init
}
function gdiffFn {
git diff --color-words
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Git ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Commans
function nrdFN {
npm run dev
}
# --------------------------------------------------------------------- @Open files ---------------------------------------------------------------------
Set-Alias -Name vimp -Value vimPackageFN
Set-Alias -Name vimr -Value vimReadmeFN
Set-Alias -Name vimg -Value vimIgnoreFN
Set-Alias -Name vimi -Value vimIndexFN
Set-Alias -Name vimw -Value vimWebpackFN
Set-Alias -Name vime -Value vimEditorconfigFN
Set-Alias -Name vimt -Value vimTsconfigFN
Set-Alias -Name vimu -Value vimUserProfileFN
function vimPackageFN {
nvim package.json
}
function vimReadmeFN {
nvim README.md
}
function vimIgnoreFN {
nvim .gitignore
}
function vimIndexFN {
nvim index.js
}
function vimWebpackFN {
nvim webpack.config.js
}
function vimEditorconfigFN {
nvim .editorconfig
}
function vimTsconfigFN {
nvim tsconfig.js
}
function vimUserProfileFN {
nvim user_profile.ps1
}
function miducoFN {
npx miduco@latest
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Open files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Modify behivior of the pws
Set-Alias -Name t -Value tabRenameFN
# --------------------------------------------------------------------- @Modify Paths ---------------------------------------------------------------------
Set-Alias -Name rmf -Value removeForceFN
function removeForceFN ($param) {
if (-not [string]::IsNullOrWhiteSpace($param)) {
$confirmation = Read-Host '¿Estás seguro de que deseas eliminar el archivo? (Y/N)'
if ($confirmation -eq 'Y') {
Write-Output ('Eliminando... ' + $param)
Remove-Item -Force $param
} else {
Write-Output 'Eliminacion cancelada'
}
} else {
Write-Output 'Ningún archivo para eliminar.'
}
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Modify Paths ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Logic for PaneComannder
# Encapsulate an arbitrary command
class PaneCommand {
[string]$Command
PaneCommand() {
$this.Command = "";
}
PaneCommand([string]$command) {
$this.Command = $command
}
[string]GetCommand() {
return $this.Command
}
[string]ToString() {
return $this.GetCommand();
}
}
# A proxy for Split Pane which takes in a command to run inside the pane
class Pane : PaneCommand {
[string]$ProfileName;
[string]$Orientation
[decimal]$Size;
Pane([string]$command) : base($command) {
$this.Orientation = '';
$this.ProfileName = "pwsh"
$this.Size = 0.5;
}
Pane([string]$command, [string]$orientation) : base($command) {
$this.Orientation = $orientation;
$this.ProfileName = "pwsh"
$this.Size = 0.5;
}
Pane([string]$command, [string]$orientation, [decimal]$size) : base($command) {
$this.Orientation = $orientation;
$this.ProfileName = "pwsh"
$this.size = $size;
}
Pane([string]$ProfileName, [string]$command, [string]$orientation, [decimal]$size) : base($command) {
$this.Orientation = $orientation;
$this.ProfileName = $ProfileName;
$this.size = $size;
}
[string]GetCommand() {
return 'split-pane --size {0} {1} -p "{2}" -c {3}' -f $this.Size, $this.Orientation, $this.ProfileName, $this.Command
}
}
class TargetPane : PaneCommand {
[int]$SelectedIndex;
TargetPane([int]$index) {
$this.SelectedIndex = $index;
}
[string]GetCommand() {
return "focus-pane --target={0}" -f $this.SelectedIndex;
}
}
class MoveFocus : PaneCommand {
[string]$direction;
MoveFocus([string]$direction) {
$this.direction = $direction;
}
[string]GetCommand() {
return 'move-focus --direction {0}' -f $this.direction;
}
}
class PaneManager : PaneCommand {
[string]$InitialCommand;
[List[PaneCommand]]$PaneCommands;
[string]$ProfileName;
[string]$DefaultOrientation;
[float]$DefaultSize;
PaneManager() {
$this.PaneCommands = [List[PaneCommand]]::new();
$this.ProfileName = "pwsh";
$this.DefaultOrientation = '-V';
$this.DefaultSize = 0.5;
$this.InitialCommand = "--maximized"
}
PaneManager([string]$ProfileName) {
$this.ProfileName = $ProfileName;
$this.DefaultOrientation = '-V';
$this.DefaultSize = 0.5;
}
[PaneManager]SetInitialCommand([string]$command) {
$this.InitialCommand = $command;
return $this;
}
[PaneManager]SetProfileName([string]$name) {
$this.ProfileName = $name;
return $this;
}
[PaneManager]SetDefaultOrientation([string]$orientation) {
$this.DefaultOrientation = $orientation;
return $this;
}
[PaneManager]SetDefaultSize([float]$size) {
$this.DefaultSize = $size;
return $this;
}
[PaneManager]SetOptions([string]$name, [string]$orientation, [float]$size) {
return $this.SetProfileName($name)
.SetDefaultOrientation($orientation)
.SetDefaultSize($size);
}
[PaneManager]AddPane([PaneManager]$manager) {
$manager.SetInitialCommand('');
$this.AddCommand($manager);
return $this;
}
[PaneManager]AddCommand([PaneCommand]$command) {
$this.PaneCommands.Add($command);
return $this;
}
[PaneManager]AddPane([string]$command, [string]$orientation, [decimal]$size) {
$newPane = $this.MakePane(
$this.ProfileName,
$command,
$orientation,
$size
);
$this.AddCommand($newPane);
return $this;
}
[Pane]MakePane($ProfileName, $command, $orientation, $size) {
$newPane = [Pane]::new($ProfileName, $command, $orientation, $size);
return $newPane;
}
[PaneManager]TargetPane([int]$index) {
$targetCommand = [TargetPane]::new($index)
$this.AddCommand($targetCommand)
return $this;
}
[PaneManager]MoveFocus([string]$direction) {
$targetCommand = [MoveFocus]::new($direction)
$this.AddCommand($targetCommand)
return $this;
}
[int]GetPaneCount() {
$count = 0;
foreach ($command in $this.PaneCommands)
{
if ($command -is [PaneManager]) {
$count += $command.GetPaneCount();
} elseif ($command -is [PaneCommand]) {
$count += 1;
}
}
return $count;
}
[string]GetCommand() {
$joinedCommands = $this.PaneCommands -join "; ";
if ($joinedCommands -eq "") {
return $this.InitialCommand;
}
$finalCommand = if ($this.InitialCommand -ne "") { "{0}; {1}" -f $this.InitialCommand, $joinedCommands} else { $joinedCommands };
return $finalCommand
}
}
# t command for open one instance of powershell divide in 3panes
function tabRenameFN {
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture("en-US")
$culture.NumberFormat.NumberDecimalSeparator = "."
$culture.NumberFormat.NumberGroupSeparator = ","
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
$paneManagerClass = ([PaneManager]::new()).
AddPane("pwsh", '-H', 0.25).
AddPane("pwsh", '-V', 0.5).
MoveFocus("up");
start wt $paneManagerClass;
}
#---------------------- [LOGGER]/[END_LOGGER]-----------------------------------------------------
function Write-Log {
param (
[string]$message,
[string]$level = "INFO",
[string]$logFile = "log.txt",
[string]$levelColor = "White",
[string]$messageColor = "White",
[switch]$D
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "[${timestamp}] [${level}] ${message}"
# Define los códigos de escape de colores
$colorCodes = @{
"Black" = "30"
"Red" = "31"
"Green" = "32"
"Yellow" = "33"
"Blue" = "34"
"Magenta" = "35"
"Cyan" = "36"
"White" = "37"
}
if ($colorCodes.ContainsKey($levelColor)) {
$levelColorCode = $colorCodes[$levelColor]
$startLevelColor = "`e[${levelColorCode}m"
$endLevelColor = "`e[0m"
# Agrega los códigos de escape de colores al nivel del registro
$logEntry = $logEntry -replace $level, "${startLevelColor}$level${endLevelColor}"
}
if ($colorCodes.ContainsKey($messageColor)) {
$messageColorCode = $colorCodes[$messageColor]
$startMessageColor = "`e[${messageColorCode}m"
$endMessageColor = "`e[0m"
# Agrega los códigos de escape de colores al mensaje del registro
#$logEntry = $logEntry -replace $message, "${startMessageColor}$message${endMessageColor}"
#$logEntry = $logEntry -replace [regex]::Escape($message), "${startMessageColor}$message${endColor}"
if ($D) {
$logEntry = $logEntry -replace [regex]::Escape($message), "${startMessageColor}$message${endColor}"
}
else {
$logEntry = $logEntry -replace $message, "${startMessageColor}$message${endMessageColor}"
}
}
Write-Host $logEntry # Imprime el registro en la consola
# Escribe el registro en el archivo de registro
Add-Content -Path $logFile -Value $logEntry
}
#-----------------------------------------------------¬
#| Ejemplo de uso del logger con colores personalizados|
#------------------------------------------------------
#Write-Log "Este es un mensaje de información" -level "INFO" -levelColor "White" -messageColor "White"
#Write-Log "¡E! Algo salió mal" -level "ERROR" -levelColor "Red" -messageColor "White"
#Write-Log "Mensaje de advertencia" -level "WARNING" -levelColor "White" -messageColor "Yellow"
#---------------------- [LOGGER]/[END_LOGGER]-----------------------------------------------------
#---------------------- [YOUTUBE]/[DOWNLOADER]-----------------------------------------------------
#$VIDEO_ID = $args[0]
#if (-not $VIDEO_ID) {
# Write-Host "ERROR: No video ID specified"
# exit 1
#}
#Write-Log "videoID: $VIDEO_ID" -level "LOGGER" -levelColor "White" -messageColor "Yellow"
#$command = "yt-dlp"
#$arguments = "https://www.youtube.com/watch?v=$VIDEO_ID", "--format", "m4a", "-o", "./tmp/$($VIDEO_ID)s.%(ext)s"
#& $command $arguments 2>&1
#---------------------- [YOUTUBE]/[END_DOWNLOADER]-----------------------------------------------------
#---------------------- [SET_VARIABLES]/[END_SETVARIABLES]-----------------------------------------------------
# Set-Item -Path "Env:NOMBRE" -Value "CHEATMODES4"
Set-Alias -Name setVar -Value setEnvVar
# Set-Item -Path "Env:"transcribeApiKey -Value "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"
function setEnvVar ($nombre, $valor) {
Set-Item -Path "Env:$nombre" -Value "$valor"
}
#---------------------- [SET_VARIABLES]/[END_SETVARIABLES]-----------------------------------------------------
# Create .gitignore file using this command:
# welc > .gitignore
Set-Alias -Name welc -Value welcFn
Set-Alias -Name cheat -Value cheatFn
Set-Alias -Name cheatM -Value cheatmodes
Import-Module $env:USERPROFILE\.config\powershell\gitIgnore.ps1
Import-Module $env:USERPROFILE\.config\powershell\cheatmodes4.ps1
# Clear console when start
cheatmodes
Start-Sleep -Seconds 1.618
Clear-Host;
# put me in dev path at start
#z dev;
# put me in isa path at start
# z isa;
z smart;