-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUltraShell.PSReadLine.ps1
More file actions
67 lines (60 loc) · 2.75 KB
/
Copy pathUltraShell.PSReadLine.ps1
File metadata and controls
67 lines (60 loc) · 2.75 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
#requires -Version 7.0
<#
.SYNOPSIS
Módulo PSReadLine de UltraShell - Configuración de línea de comandos
#>
<#
.SYNOPSIS
Inicializa PSReadLine con configuración personalizable desde config.psd1.
.DESCRIPTION
Configura colores, keybindings, predicciones e historial de PSReadLine.
PredictionSource es configurable desde config.psd1 (clave PSReadLinePredictionSource).
Valores válidos: None, History, HistoryAndPlugin.
.OUTPUTS
[bool] $true si se configuró correctamente.
.EXAMPLE
Initialize-PSReadLine
#>
function Initialize-PSReadLine {
[CmdletBinding()][OutputType([bool])] param()
try {
if (-not (Get-Module -ListAvailable -Name 'PSReadLine')) {
Write-ProfileMessage "PSReadLine no está disponible" -Level "Warning"
return $false
}
$defaultPredictionSource = 'HistoryAndPlugin'
$predictionSource = $defaultPredictionSource
$configuredPredictionSource = [string]$Script:Config.PSReadLinePredictionSource
$validPredictionSources = @('None', 'History', 'HistoryAndPlugin')
if (-not [string]::IsNullOrWhiteSpace($configuredPredictionSource)) {
$matchedPredictionSource = $validPredictionSources | Where-Object { $_ -ieq $configuredPredictionSource } | Select-Object -First 1
if ($matchedPredictionSource) {
$predictionSource = $matchedPredictionSource
}
else {
Write-ProfileMessage "PSReadLinePredictionSource inválido ('$configuredPredictionSource'). Se usará '$defaultPredictionSource'." -Level "Warning"
}
}
Set-PSReadLineOption -PredictionSource $predictionSource
Set-PSReadLineOption -MaximumHistoryCount 4000
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -EditMode Windows
Set-PSReadLineOption -BellStyle None
Set-PSReadLineOption -Colors @{
Command = 'Cyan'; Parameter = 'DarkCyan'; Operator = 'DarkGray'
Variable = 'Green'; String = 'Yellow'; Number = 'Magenta'
Member = 'DarkGreen'; Type = 'DarkYellow'; Comment = 'DarkGray'
Keyword = 'Blue'; Error = 'Red'
}
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Ctrl+d -Function DeleteChar
Set-PSReadLineKeyHandler -Key Ctrl+w -Function BackwardDeleteWord
Write-ProfileMessage "PSReadLine configurado (predicción: $predictionSource)" -Level "Success"
return $true
}
catch {
Write-ProfileMessage "Error al configurar PSReadLine: $($_.Exception.Message)" -Level "Error"
return $false
}
}