diff --git a/module/CHANGELOG-CN.md b/module/CHANGELOG-CN.md index e1b0cc1..809b8aa 100644 --- a/module/CHANGELOG-CN.md +++ b/module/CHANGELOG-CN.md @@ -3,6 +3,12 @@ 简体中文
+## 5.1.3 (2024/11/30) + +- 修复拥有 `hooks.ps1` 的补全命令的动态补全不生效的问题。 +- 当模块需要更新时,会尝试多种更新方式。 +- 其他的优化和修复。 + ## 5.1.2 (2024/11/27) - 由于未来的 Windows Terminal 的变化,将导致在补全菜单中无法正常显示 😄🤔😎,因此这三个默认特殊符号将改变。 diff --git a/module/CHANGELOG.md b/module/CHANGELOG.md index 5a13656..9efd5b0 100644 --- a/module/CHANGELOG.md +++ b/module/CHANGELOG.md @@ -3,6 +3,12 @@ English +## 5.1.3 (2024/11/30) + +- Fix the issue of dynamic completion not taking effect for commands with `hooks.ps1`. +- When a module needs to be updated, it will try multiple update methods. +- Other optimizations and fixes. + ## 5.1.2 (2024/11/27) - Due to future changes in Windows Terminal, 😄🤔😎 will not be displayed properly in the completion menu, so these three default special symbols will change. diff --git a/module/PSCompletions/PSCompletions.psd1 b/module/PSCompletions/PSCompletions.psd1 index 7be3a23..64fb8d0 100644 --- a/module/PSCompletions/PSCompletions.psd1 +++ b/module/PSCompletions/PSCompletions.psd1 @@ -9,7 +9,7 @@ @{ RootModule = 'PSCompletions.psm1' - ModuleVersion = '5.1.2' + ModuleVersion = '5.1.3' GUID = '00929632-527d-4dab-a5b3-21197faccd05' diff --git a/module/PSCompletions/core/completion/win.ps1 b/module/PSCompletions/core/completion/win.ps1 index 185ff44..d0ff4c1 100644 --- a/module/PSCompletions/core/completion/win.ps1 +++ b/module/PSCompletions/core/completion/win.ps1 @@ -9,16 +9,6 @@ return } - # Windows PowerShell 5.x - if ($PSEdition -ne 'Core') { - $PSCompletions.config.horizontal = '-' - $PSCompletions.config.vertical = '|' - $PSCompletions.config.top_left = '+' - $PSCompletions.config.bottom_left = '+' - $PSCompletions.config.top_right = '+' - $PSCompletions.config.bottom_right = '+' - } - # 是否是按下空格键触发的补全 $space_tab = if ($buffer[-1] -eq ' ') { 1 }else { 0 } # 使用正则表达式进行分割,将命令行中的每个参数分割出来,形成一个数组, 引号包裹的内容会被当作一个参数,且数组会包含 "--" @@ -80,7 +70,7 @@ $tool_tip = $completion.ToolTip } else { - # 如果是内置命令,由于其 ToolTip 写法很奇怪,会导致显示的内容有些问题 + # XXX: 如果是内置命令(如: Get-Content等),其 ToolTip 写法很奇怪,会导致显示的内容有些问题,这里做了特殊处理 $tool_tip = @() foreach ($tip in $completion.ToolTip) { $tip = $tip -replace '\s{2}', ' ' @@ -150,15 +140,6 @@ $filter_list = $PSCompletions.get_completion() if ($PSCompletions.config.enable_menu -eq 1) { - # Windows PowerShell 5.x - if ($PSEdition -ne 'Core') { - $PSCompletions.config.horizontal = '-' - $PSCompletions.config.vertical = '|' - $PSCompletions.config.top_left = '+' - $PSCompletions.config.bottom_left = '+' - $PSCompletions.config.top_right = '+' - $PSCompletions.config.bottom_right = '+' - } $PSCompletions.menu.show_module_menu($filter_list) } else { diff --git a/module/PSCompletions/core/init.ps1 b/module/PSCompletions/core/init.ps1 index 47df6f5..ee600eb 100644 --- a/module/PSCompletions/core/init.ps1 +++ b/module/PSCompletions/core/init.ps1 @@ -1,7 +1,7 @@ using namespace System.Management.Automation $_ = Split-Path $PSScriptRoot -Parent New-Variable -Name PSCompletions -Value @{ - version = '5.1.2' + version = '5.1.3' path = @{ root = $_ completions = Join-Path $_ 'completions' @@ -509,11 +509,9 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod get_completion { $input_arr = [array]$input_arr - if ($PSCompletions.config.comp_config.$root.disable_hooks -eq 1) { - # 使用 hooks 覆盖默认的函数,实现在一些特殊的需求,比如一些补全的动态加载 - if ($PSCompletions.config.comp_config.$root.disable_hooks -ne 1) { - . "$($PSCompletions.path.completions)/$root/hooks.ps1" - } + # 使用 hooks 覆盖默认的函数,实现在一些特殊的需求,比如一些补全的动态加载 + if ($PSCompletions.config.comp_config.$root.disable_hooks -notin @($null, 1)) { + . "$($PSCompletions.path.completions)/$root/hooks.ps1" } if (!$PSCompletions.completions_data.$root) { $common_options = @() @@ -1064,6 +1062,15 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod init_data { $language = if ($PSCompletions.language -eq 'zh-CN') { 'zh-CN' }else { 'en-US' } $PSCompletions.info = $PSCompletions.ConvertFrom_JsonToHashtable($PSCompletions.get_raw_content("$($PSCompletions.path.completions)/psc/language/$language.json")).info } + # XXX: 在 Windows PowerShell 5.x 中,边框使用以下符号以处理兼容性问题 + if ($PSEdition -ne 'Core') { + $PSCompletions.config.horizontal = '-' + $PSCompletions.config.vertical = '|' + $PSCompletions.config.top_left = '+' + $PSCompletions.config.bottom_left = '+' + $PSCompletions.config.top_right = '+' + $PSCompletions.config.bottom_right = '+' + } } Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod get_length { param([string]$str) @@ -1338,8 +1345,21 @@ if ($PSCompletions.config.enable_module_update -notin @(0, 1)) { if ($PSCompletions.version_list[0] -ne $PSCompletions.version) { $PSCompletions.wc.DownloadFile("$($PSCompletions.url)/module/CHANGELOG.json", (Join-Path $PSCompletions.path.temp 'CHANGELOG.json')) $null = $PSCompletions.confirm_do($PSCompletions.info.module.update, { - $PSCompletions.write_with_color($PSCompletions.replace_content($PSCompletions.info.module.updating)) - Update-Module PSCompletions -RequiredVersion $PSCompletions.version_list[0] -Force -ErrorAction Stop + $cmd_list = @( + "Update-Module PSCompletions -RequiredVersion $($PSCompletions.version_list[0]) -Force -ErrorAction Stop", + "Update-PSResource PSCompletions -Version $($PSCompletions.version_list[0]) -Force -ErrorAction Stop", + "Scoop update pscompletions" + ) + foreach ($update_cmd in $cmd_list) { + try { + $PSCompletions.write_with_color($PSCompletions.replace_content($PSCompletions.info.module.updating)) + Invoke-Expression $update_cmd + break + } + catch { + Write-Host $_ -ForegroundColor Red + } + } }) } else { diff --git a/module/version.txt b/module/version.txt index 61fcc87..cdb98d2 100644 --- a/module/version.txt +++ b/module/version.txt @@ -1 +1 @@ -5.1.2 +5.1.3