-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ninmonkey.Console.psm1
798 lines (656 loc) · 22.7 KB
/
Ninmonkey.Console.psm1
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
787
788
789
790
791
792
793
794
795
796
797
798
using namespace System.Collections.Generic
$searchRoot = Join-path $PSScriptRoot 'public_autoloader/cmd-git'
$found = gci $searchRoot *.ps1 -Recurse
$SearchRoot
| Join-String -f '::SearchRoot: {0}'
| write-verbose
foreach($obj in $found) {
$Obj | Join-String -f '::Dotsourcing: {0}'
| write-verbose
. $Obj
}
# public_autoloader\cmd-git\Getting.Resolve-Symbol.ps1
# code below is from a long time ago. above here is 2023-06-01
# __countDuplicateLoad -key 'Nimonkey.Console.psm1'
# using namespace System.Management.Automation
<# init
todo: better config system, than copying my profile
#>
$__origPrompt = $function:prompt
$PSDefaultParameterValues['Select-NinProperty:Out-Variable'] = 'SelProp'
$PSDefaultParameterValues['Write-ConsoleLabel:fg'] = '7FB2C1'
# $PSDefaultParameterValues['Write-Text:AsString'] = $true
$script:__disabled_UntilIUpdateSeeminglySciMerge = $true
. (Get-Item -ea stop (Join-Path $PSScriptRoot 'private/safe_prompt.ps1'))
# disable for now, because shell integration breaks it
& {
$hasFunc = (Get-PSReadLineKeyHandler -Bound -Unbound | ForEach-Object Function ) -contains 'ShowCommandHelp'
if ($hasFunc) {
Set-PSReadLineKeyHandler -Key 'f12' -Function ShowCommandHelp
}
}
Set-PSReadLineOption -Colors @{
Comment = '#E58BEB' # " e[38;2;229;139;235m"
}
<#
future:
- [ ] use package
#>
<#
section: seeminglyScience Private
#>
# . 'C:\Users\cppmo_000\Documents\2020\powershell\MyModules_Github\Ninmonkey.Console\private\refactor to csharp\EncodingCompletion.ps1'
$__Config = @{
includeAliasesUnicode = $true
includePSReadline = $false
DisableTabCompleters = $true
}
. (Get-Item -ea stop (Join-Path $PSScriptRoot 'root_autoloader.ps1'))
# if ($False) {
# try {
# $FileName = ('{0}\public_autoloader\__init__.ps1' -f $psscriptroot)
# if (Test-Path $FileName ) {
# . $FileName
# }
# } catch {
# Write-Error "public_autoloader error: '$fileName'"
# }
# }
# if ($true) {
# $base = $psscriptroot ?? ('C:\Users\cppmo_000\Documents\2021\Powershell\My_Github\Ninmonkey.Console')
# . (Get-Item -ea Stop (Join-Path $base 'public_autoloader\__init__.ps1'))
# . (Get-Item -ea Stop (Join-Path $PSScriptRoot 'public_autoloader\__init__.ps1'))
# }
# function prompt {
# "`n`n>"
# }
# throw 'stop here debug'
$psreadline_extensions = @(
'smart_brackets_braces' # auto add/close quotes and braces
'ParenthesizeSelection' # type alt+( to surround existing `ession in parenthesis
# 'ToggleQuoteArgument' # cycles between qoute types, and none.
'ExpandAliases' # expands aliases.
'IndentSelections_Jaykul' # indent/dedent selected text: alt+[ or ]
)
if ('InlineAlwaysImportFirst') {
# $_cmds = Get-Command -m AwsLambdaPSCore
# nin.Help.Command.OutMarkdown -Debug -verbose -inputobject $_cmds
function nin.PSModulePath.Clean {
<#
.SYNOPSIS
-1] remove invalid paths
-2] remove duplicate paths, preserving sort order
-3] remove any all-whitespace values
-4] remove obsolete import path from 2021
.NOTES
todo: use that hashset case-insesitive duplication and preserve ordering
.EXAMPLE
nin.CleanPSModulePath
.link
nin.PSModulePath.Clean
.link
nin.PSModulePath.Add
.link
nin.PSModulePath.AddNamedGroup
#>
[CmdletBinding()]
param(
# return the new value
# cleans up then returns the new value
[Alias('WhatIf')]
[switch]$PassThru,
# this actually writes to the env var
[switch]$Write
)
$Env:PSMODulePath
| Write-Verbose
Write-Warning "todo: ensure duplicates are removed: $PSCOmmandPath"
$records = $Env:PSMODulePath -split ([IO.Path]::PathSeparator)
| Where-Object { $_ } # drop false and empty strings
| Where-Object { -not [String]::IsNullOrWhiteSpace( $_ ) } # drop blank
$records | Join-String -op "initial: `n" -FormatString "`n- {0}" | Write-Debug
# $records | Join-String -op "`n- " -sep "`n- " -DoubleQuote | write-verbose
# $records | Join-String -op 'Was:' | Write-Debug
$records = $records
| Where-Object { $_ -notmatch ([Regex]::Escape('C:\Users\cppmo_000\SkyDrive\Documents\2021')) }
$records | Join-String -op "initial: `n" -FormatString "`n- {0}" | Write-Debug
$finalPath = $records | Join-String -sep ([IO.Path]::PathSeparator)
$finalPath | Join-String -op 'finalPath = ' | Write-Verbose
if ($Write) {
Write-Verbose 'wrote PSModulePath'
$Env:PSMODulePath = $finalPath
}
if ($PassThru) {
return $finalPath
}
}
function nin.PSModulePath.Add {
<#
.SYNOPSIS
add paths to PSModulePath, optionally require existing, or distinct
.EXAMPLE
PS> nin.CleanPSModulePath
.link
nin.PSModulePath.Clean
.link
nin.PSModulePath.Add
.link
nin.PSModulePath.AddNamedGroup
#>
[CmdletBinding()]
param(
[ArgumentCompletions('E:\PSModulePath.2023.root')]
[Parameter(Mandatory, Position = 0)]
[string[]]$LiteralPath,
[switch]$RequireExist,
# prefix rather than add to end?
[Alias('ToFront')]
[switch]$AddToFront
# [string[]]$GroupName
)
$Env:PSModulePath -split ([IO.Path]::PathSeparator) | Join-String -op "`n- " -sep "`n- " -DoubleQuote
| Join-String -op 'start: ' | Write-Debug
Write-Warning 'todo: ensure duplicates are removed'
foreach ($curPath in $LiteralPath) {
$Item = $curPath
if ($RequireExists) {
$Item = Get-Item -ea stop $curPath
if (-not (Test-Path $Item) ) {
# does not always trigger as expected?
Write-Error "Not Existing: $Item"
continue
}
}
$records = $Env:PSModulePath -split ([IO.Path]::PathSeparator)
if ($records -contains $Item) { continue }
Join-String -inp $Item -FormatString 'Adding Path: <{0}>' | Write-Verbose
if ($AddToFront) {
$Env:PSModulePath = @(
$Item
$Env:PSModulePath
) | Join-String -sep ([IO.Path]::PathSeparator)
}
else {
$Env:PSModulePath = @(
$Env:PSModulePath
$Item
) | Join-String -sep ([IO.Path]::PathSeparator)
}
# Join-String -inp $Item 'adding: "{0}" to $PSModulePath'
}
$Env:PSModulePath -split ([IO.Path]::PathSeparator) | Join-String -op "`n- " -sep "`n- " -DoubleQuote
| Join-String -op 'end : ' | Write-Debug
}
function nin.PSModulePath.AddNamedGroup {
<#
.synopsis
either add a group of custom PSModulePaths by GrupName else full name
.example
nin.PSModulePath.AddNamedGroup -GroupName AWS, JumpCloud -verbose -debug4
.example
.example
nin.PSModulePath.Clean
nin.PSModulePath.AddNamedGroup -GroupName AWS, JumpCloud -verbose -debug
nin.PSModulePath.Add -verbose -debug -RequireExist -LiteralPath @(
'E:\PSModulePath.2023.root\Main'
'H:\data\2023\pwsh\PsModules\ExcelAnt\Output'
)
#>
[CmdletBinding(DefaultParameterSetName = 'GroupName')]
param(
[ArgumentCompletions('AWS', 'Disabled', 'JumpCloud', 'Main')]
[Parameter(Mandatory, Position = 0, ParameterSetName = 'GroupName')]
[string[]]$GroupName,
[Alias('PSPath', 'Path', 'Name')]
[Parameter(Mandatory, ParameterSetName = 'LiteralPath', ValueFromPipelineByPropertyName)]
$LiteralPath
)
$Env:PSModulePath -split ([IO.Path]::PathSeparator) | Join-String -op "`n- " -sep "`n- " -DoubleQuote
| Join-String -op 'Was:' | Write-Debug
switch ( $PSCmdlet.ParameterSetName ) {
'GroupName' {
foreach ($item in $GroupName) {
$mappedGroupPath = Join-Path 'E:\PSModulePath.2023.root' $Item
nin.PSModulePath.Add -LiteralPath $mappedGroupPath -RequireExist -Verbose -Debug
}
continue
}
'LiteralPath' {
nin.PSModulePath.Add -LiteralPath $LiteralPath -RequireExist -Verbose -Debug
continue
}
default { throw "UnhandledSwitch ParameterSetItem: $Switch" }
}
}
}
if ( -not $__disabled_UntilIUpdateSeeminglySciMerge ) {
$private_seeminglySci = @(
'seeminglySci_import'
'NamespaceAwareCompletion'
# 'Get-EnumInfo'
# 'EncodingCompletion'
)
if ($psEditor) {
Write-Debug 'loading namespaceAwareCompletions'
# see: <https://github.com/SeeminglyScience/dotfiles/b lob/a7a9bcf3624efe5be4988922ba2e35e8ff2fcfd8/PowerShell%2Fprofile.ps1#L147>
# $private_seeminglySci.Remove('NamespaceAwareCompletion')
$private_seeminglySci = $private_seeminglySci -ne 'NamespaceAwareCompletion'
}
foreach ($file in $private_seeminglySci) {
try {
# Write-Warning "file: seeminglySci -> : $File"
if (Test-Path ('{0}\private\seeminglySci\{1}.ps1' -f $psscriptroot, $file)) {
}
else {
Write-Error "Import: failed: private_seeminglySci: private: $File"
}
. ('{0}\private\seeminglySci\{1}.ps1' -f $psscriptroot, $file)
}
catch {
Write-Error -ErrorRecord $_ -Message "Loading '$file' failed!`n$_" -ea stop
}
}
}
<#
section: Private
#>
$private = @(
'Toast-LogTestNetResult'
'pester/Test-PesterLinesAreEqual'
)
foreach ($file in $private) {
if (Test-Path ('{0}\private\{1}.ps1' -f $psscriptroot, $file)) {
}
else {
Write-Error "Import: private: failed: private: $File"
}
. ('{0}\private\{1}.ps1' -f $psscriptroot, $file)
}
<#
section: native apps
#>
$public_NativeWrapper = @(
# 'Invoke-IPython'
# 'Invoke-RipGrepChildItem'
)
foreach ($file in $public_NativeWrapper) {
if (Test-Path ('{0}\public\native_wrapper\{1}.ps1' -f $psscriptroot, $file)) {
}
else {
Write-Error "Import: failed: public\native_wrapper: $File"
}
. ('{0}\public\native_wrapper\{1}.ps1' -f $psscriptroot, $file)
}
Export-ModuleMember -Function $public_NativeWrapper
$public_toDotSource = @(
# 2023-08-03
# 'Format-Join.Csv' # Format-Join.Csv = { 'Join.Csv' }
# misc
'Get-NinMyVSCode'
'Join-Regex'
'Resolve-CommandName'
'Test-UserIsAdmin'
'Get-NinModule'
'Import-NinModule'
'ConvertTo-Timespan'
'Invoke-Wget'
'Edit-GitConfig'
'Get-NinAlias'
'Find-GitRepo'
'Write-ConsoleText'
'Write-ConsoleHorizontalRule'
'Import-NinPSReadLineKeyHandler'
# console formatting
'Write-ConsoleLabel'
'Write-ConsoleHeader'
'Write-ConsoleNewline'
'Format-Hashtable'
'Format-ControlChar'
# 'Format-ControlChar2'
# unicode + encoding
'Get-TextEncoding'
'Get-UnicodeInfo'
# other core funcs
'Get-NativeCommand'
'Invoke-NativeCommand'
# converters
'ConvertTo-Number'
'ConvertTo-HexString'
'ConvertTo-Base64String'
'ConvertTo-PropertyList'
# inspection
'Get-StaticProperty'
# misc
'Select-NinProperty'
# the rest
'Compare-Directory'
'Get-NinCommandProxy'
'Export-PlatformFolderPath'
# history
'Format-History'
'Format-MeasureCommand'
'Format-TestConnection'
'Get-ConsoleEncoding'
'Get-Docs'
'Write-AnsiHyperlink'
'Trace-NinCommand'
'Format-Predent'
'Sort-Hashtable'
'Get-NinTypeData'
# 'Get-NinFormatData'
'Set-NinLocation'
'Set-ConsoleEncoding'
'Start-LogTestNet'
'Test-Net'
'Get-EnumInfo'
'Format-FileSize'
'Format-NullText'
# 'ConvertTo-PropertyList'
'Get-NinCommandSyntax'
'Format-TypeName'
'Format-GenericTypeName'
'Get-ObjectProperty'
'Test-NullArg'
'Get-NinChildItem'
'Get-ObjectType'
'Get-NinAppxPackage'
'Invoke-Explorer'
'Get-TerminalName'
'Format-PrettyJson'
'Format-HashTableList'
# 'Get-NinNewestItem'
'Out-Fzf'
)
<#
section: public
#>
foreach ($file in $public_toDotSource) {
if (Test-Path ('{0}\public\{1}.ps1' -f $psscriptroot, $file)) {
# good
}
else {
Write-Error "Import: failed: public: $File"
}
. ('{0}\public\{1}.ps1' -f $psscriptroot, $file)
}
if ($public_toDotSource.count -ge 1 ) {
Write-Warning 'Imports not fully merged into autoloader: $public_ToDotSource '
}
$functionsToExport = @(
# 2023-08-03
'Format-Join.Csv' # = # Format-Join.Csv = { 'Join.Csv' }
'nin.PSModulePath.Add'
'nin.PSModulePath.AddNamedGroup'
'nin.PSModulePath.Clean'
# misc
'ConvertTo-Timespan'
'Get-NinModule'
'Get-NinMyVSCode'
'Import-NinModule'
'Import-NinPSReadLineKeyHandler'
'Join-Regex'
'Resolve-CommandName'
'Select-NinProperty'
'Test-UserIsAdmin'
# console formatting
'Find-GitRepo'
'Invoke-Wget'
'Write-ConsoleHeader'
'Write-ConsoleHorizontalRule'
'Write-ConsoleLabel'
'Write-ConsoleNewline'
'Write-ConsoleText'
# unicode + encoding
'Compare-Directory'
'Get-NinCommandProxy'
'Get-TextEncoding'
'Get-UnicodeInfo'
# converters
'ConvertTo-Base64String'
'ConvertTo-HexString'
'ConvertTo-Number'
'ConvertTo-PropertyList'
# the rest
'Edit-GitConfig'
'Export-PlatformFolderPath'
'Format-GenericTypeName'
'Format-Hashtable'
'Format-TypeName'
'Get-NativeCommand'
'Invoke-NativeCommand'
# history
# inspection
'Get-StaticProperty'
'Get-NinAlias'
# 'Get-NinNewestItem'
'Format-Predent'
'ConvertTo-PropertyList'
'Format-ControlChar'
'Format-FileSize'
'Format-NullText'
'Get-NinAppxPackage'
'Get-ObjectProperty'
'Get-ObjectType'
'Invoke-Explorer'
'Sort-Hashtable'
'Test-NullArg'
'Trace-NinCommand'
'Format-History'
'Format-MeasureCommand'
'Format-TestConnection'
'Get-ConsoleEncoding'
'Get-Docs'
'Get-EnumInfo'
# 'Get-EnumInfo'
'Get-NinChildItem'
'Get-NinCommandSyntax'
# 'Get-NinFormatData'
'Get-NinTypeData'
'Get-TerminalName'
'Set-NinLocation'
'Write-AnsiHyperlink'
'Invoke-IPython'
'Invoke-RipGrepChildItem'
'Set-ConsoleEncoding'
'Start-LogTestNet'
'Test-Net'
# 'Get-ElementName'
# seemingly-sci
'ConvertTo-Base64String'
'ConvertTo-HexString'
'ConvertTo-Number'
'Format-HashTableList'
'Format-PrettyJson'
'Out-Fzf'
'Test-PesterLinesAreEqual'
# Pester: to remove from Public scope; should be private or only loaded by pester
)
Export-ModuleMember -Function $functionsToExport
if ($functionsToExport.count -ge 1 ) {
Write-Warning 'Imports not fully merged into autoloader: $functionsToExport '
}
<#
section: FormatData
#>
$formatData = @(
# 'System.RuntimeType'
# 'Microsoft.PowerShell.Commands.TestConnectionCommand'
# 'Nin.PropertyList'
)
<#
see also:
Trace-Command -Name FormatViewBinding, FormatFileLoading {
# Update-FormatData -AppendPath 'C:\Users\cppmo_000\Documents\2020\powershell\MyModules_Github\Ninmonkey.Console\public\FormatData\Nin.PropertyList.Format.ps1xml'
get-date | prop | ft
} -Verbose -PSHost
#>
function Enable-NinCoreAlias {
<#
.synopsis
loads the "core" / main set of aliases. Call this in your profile.
.example
PS> Import-Module Ninmonkey.Console; Enable-NinCoreAlias
.notes
future: Move more 'aliasesToExport' aliases below, to either here, or Ninmonkey.Profile
#>
$splat = @{
ErrorAction = 'ignore'
Force = $true
PassThru = $true
Scope = 'script'
}
$aliases = @(
# '# 2023-08-03
'Join.Csv' # = # Format-Join.Csv = { 'Join.Csv' }'
# group: builtins
Set-Alias @splat -Name 'io' -Value 'ninmonkey.console\Inspect-ObjectProperty'
Set-Alias @splat -Name 'ls' -Value 'Microsoft.PowerShell.Management\Get-ChildItem'
Set-Alias @splat -Name 'impo' -Value 'Microsoft.PowerShell.Core\Import-Module'
Set-Alias @splat -Name 'jStr' -Value 'Microsoft.PowerShell.Utility\Join-String'
Set-Alias @splat -Name 'Sc' -Value 'Microsoft.PowerShell.Management\Set-Content'
Set-Alias @splat -Name 'Gcl' -Value 'Microsoft.PowerShell.Management\Get-Clipboard'
Set-Alias @splat -Name 'Cl' -Value 'Microsoft.PowerShell.Management\Set-Clipboard'
Set-Alias @splat -Name 'Touch' -Value 'Microsoft.PowerShell.Management\New-Item'
Set-Alias @splat -Name 'to->Json' -Value 'Microsoft.PowerShell.Utility\ConvertTo-Json'
Set-Alias @splat -Name 'to->Csv' -Value 'Microsoft.PowerShell.Utility\ConvertTo-Csv'
Set-Alias @splat -Name 'from->Json' -Value 'Microsoft.PowerShell.Utility\ConvertFrom-Json'
Set-Alias @splat -Name 'from->Csv' -Value 'Microsoft.PowerShell.Utility\ConvertFrom-Csv'
# Set-Alias @splat -Name 'rolve->Cmd' -Value 'Ninmonkey.Console\Resolve-CommandName'
# group: external modules
Set-Alias @splat -Name 'Fm' -Value 'ClassExplorer\Find-Member'
Set-Alias @splat -Name 'fime' -Value 'ClassExplorer\Find-Member'
# internal funcs
Set-Alias @splat -Name 'Label' -Value 'Ninmonkey.Console\Write-ConsoleLabel'
if ($False) {
'missing, NYI merged into here '
Set-Alias @splat -Name 'Str' -Value 'Join-StringStyle'
}
)
# | _sortBy_Get-Alias
$Aliases | Write-Information
Write-Warning 'remember to import: "_sortBy_Get-Alias"'
Export-ModuleMember -Alias $aliases
}
$executionContext.SessionState.Module.OnRemove = {
New-BurntToastNotification -Text 'Module:NinConsole', 'onRemoveEvent fired' -Silent
Get-Command ls -All | Format-Table | Out-String | Write-Warning
Write-Warning 'alias "ls" isn''t reverting correctly, until next import'
Remove-Alias 'ls'# -ea ignore
# warning still not automatic
Set-Alias 'ls' 'Microsoft.PowerShell.Management\GetChildItem' -Scope Global
Get-Command ls -All | Format-Table | Out-String | Write-Warning
}
Export-ModuleMember -Function 'Enable-NinCoreAlias'
<#
Several bugs occur if 'Enable-NinCoreAlias' isn't ran, because
[1] they are not marked as aliases, so they are not unloaded
they end up pointing to 'ls.exe', not 'gci'
when either Module is unloaded, or, Module is imported again
[2] or makes ninmonkey.profile have errors for not fully loading aliases first
could fix using
[1] always load aliases, or
[2] cleanup on module uevent, or
[3] minimal module that contains the aliases, removing the dynamic requirement
#>
Enable-NinCoreAlias
foreach ($typeName in $formatData) {
$FileName = ('{0}\public\FormatData\{1}.Format.ps1xml' -f $psscriptroot, $typeName)
Get-Item $FileName -ea Continue
if (Test-Path $FileName ) {
Update-FormatData -PrependPath $FileName
Write-Verbose "Imported: FormatData: [$TypeName] $FileName"
}
else {
Write-Error "Import: failed: FormatData: [$TypeName] $FileName"
}
}
if ($true) {
$eaIgnore = @{ ErrorAction = 'Ignore' }
# toggle auto importing of aliases', otherwise only use new-alias
New-Alias @eaIgnore 'Docs' -Value 'Get-Docs' -Description 'Jump to docs by language'
New-Alias @eaIgnore 'IPython' -Value 'Invoke-IPython' -Description 'ipython.exe defaults using my profile'
# this wasn't loading below, maybe because old system
New-Alias @eaIgnore 'Select->Property' -Value Select-NinProperty
# now set as an alias: New-Alias @eaIgnore 'Goto' -Value Set-NinLocation -Description 'a more flexible version of Set-Location / cd'
New-Alias @eaIgnore 'Here' -Value Invoke-Explorer -Description 'Open paths in explorer'
# Set-Alias 'Cd' -Value 'Set-NinLocation' -ea Continue #todo: make this opt in
# class-explorer
New-Alias @eaIgnore 'Fm' -Value 'ClassExplorer\Find-Member' -Description 'uses ClassExplorer'
New-Alias @eaIgnore 'Fime' -Value 'ClassExplorer\Find-Member' -Description 'uses ClassExplorer'
New-Alias @eaIgnore -Name 'Get-EnumInfo' -Value 'Get-EnumInfo'
$aliasesToExport = @(
'H1'
'Hr'
'EnumInfo' # Get-EnumInfo
'Goto'
'nLs' # Get-NinChildItem
'LsGit' # Find-GitRepo
# 'Cd'
'Docs'
'Here'
'IPython'
'Resolve->Cmd'
'Select->Property' # Select-NinProperty
'HelpHistory' # Find-HelpFromHistory
# console formatting
'Format-Indent'
'Label'
'Br'
'Import-NinKeys' # Import-NinPSReadLineKeyHandler
# misc
'DiffDir'
'RelativeTs' # ConvertTo-Timespan
# history
# which alias for 'Write-ConsoleText'?
# 'Text' # warning: pansi uses alias 'text'
'Write-Text'
'PrettyJson'
'Prop'
'Fm'
'TypeOf'
## seemingly sci
'Default'
'Convert'
# 'NameOf'
'Base64'
'Hex'
'Number'
'Bits'
'Format-HashTable'
# inspection
'StaticMemberProp' # <-- Get-StaticProperty
)
Export-ModuleMember -Alias $aliasesToExport
if ($__Config.includeAliasesUnicode) {
$aliasesUnicode_ToExport = @(
'Json🎨'
# 'Format-HashTable🎨'
)
Export-ModuleMember -Alias $aliasesUnicode_ToExport
}
}
if ( $__Config.DisableTabCompleters) {
Write-Verbose 'ninConsole => loaders migrating to typewriter' -Verbose
}
else {
Write-Verbose 'ninConsole => loaders migrating to typewriter' -Verbose
$FileName = ('{0}\public\completer\{1}' -f $psscriptroot, 'Completer-Loader.ps1')
. $FileName
if ( ($__ninConfig)?.HackSkipLoadCompleters ) {
Write-Warning '[w] root ⟹ Completer-Loader: Skipped'
}
else {
Write-Warning '[w] root ⟹ Completer-Loader: Invoke-Build...'
$curSplat = @{
# Verbose = -Verbose
# Debug = -Debug
# infa = 'Continue'
# ea = 'Continue'
}
Build-CustomCompleter @curSplat
Import-CustomCompleter @curSplat
Import-GeneratedCompleter @curSplat
# this version works, run it last.
. (Get-Item (Join-Path $PSScriptRoot '/public/PSReadLine/native-dotnet-completer.ps1'))
}
}