Skip to content

Commit

Permalink
Merge pull request #20 from abgox/module
Browse files Browse the repository at this point in the history
fix(module): update version to 4.2.7
  • Loading branch information
abgox authored Aug 12, 2024
2 parents c676989 + d43a9c7 commit 43033d5
Show file tree
Hide file tree
Showing 10 changed files with 527 additions and 331 deletions.
21 changes: 21 additions & 0 deletions module/CHANGELOG-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
<a href="./CHANGELOG-CN.md">简体中文</a>
</p>

## 4.2.7 (2024/8/12)

- `PSCompletions` 模块会占用两个全局命名,`$PSCompletions`(变量) 和 `PSCompletions`(函数)
- 现在,它们都为只读,强行覆盖会报错,防止误操作导致模块失效
-`PSCompletions`(函数) 可以通过配置修改函数名
- 添加一个配置项 `function_name`, 默认值为 `PSCompletions`

- 设置: `psc config function_name <name>`
- 使用场景:
- 当你或其他模块需要定义一个函数,名字刚好也必须为 `PSCompletions`
- 你可以通过 `function_name` 将本模块的函数修改为一个不冲突的名字
- 需要注意:
- `PSCompletions`(函数) 可以通过配置修改,但 `$PSCompletions`(变量) 是无法修改的
- 当你需要定义一个变量,名字刚好也必须为 `$PSCompletions`
- 无法解决,要么你不使用 `PSCompletions` 模块,要么给你要定义的变量改个名字

- 对 PowerShell 内置命令的 ToolTip 提示信息简单处理,优化显示
- 当菜单显示后,输入字符进行过滤不再更改菜单的宽度
- 修复了可以设置一个已存在的命令为别名的bug
- 优化逻辑运算,移除一些多余的运算

## 4.2.6 (2024/8/10)

- 修复补全项列表为空的bug
Expand Down
19 changes: 19 additions & 0 deletions module/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
<a href="./CHANGELOG.md">English</a>
</p>

## 4.2.7 (2024/8/12)

- `PSCompletions` module will take up two global names, `$PSCompletions` (variable) and `PSCompletions` (function).
- Now, they are both read-only, and trying to overwrite will have an error, preventing accidental operation from causing the module to fail.
- However, `PSCompletions` (function) can be configured to change the function name.
- Add a configuration item `function_name`, with a default value of `PSCompletions`.
- Setting: `psc config function_name <name>`
- Use in the following case:
- When you need to define a function, the name must be `PSCompletions`.
- You can use `function_name` to rename the function of this module to a non-conflicting name.
- Note:
- `PSCompletions` (function) can be configured, but `$PSCompletions` (variable) cannot be modified.
- When you need to define a variable, the name must be `$PSCompletions`.
- It cannot be solved, either you don't use `PSCompletions` module, or you give the variable you define a different name.
- Simple processing of ToolTip information for `PowerShell` commands, optimized display.
- When the menu is displayed, filtering by input characters no longer changes the width of the menu.
- Fix a bug where you could set an existing command as an alias.
- Optimize logical operations, remove some unnecessary operations.

## 4.2.6 (2024/8/10)

- Fix a bug where the list of completions list was empty.
Expand Down
20 changes: 9 additions & 11 deletions module/PSCompletions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@

@{

RootModule = 'PSCompletions.psm1'
RootModule = 'PSCompletions.psm1'

ModuleVersion = '4.2.6'
ModuleVersion = '4.2.7'

GUID = '00929632-527d-4dab-a5b3-21197faccd05'
GUID = '00929632-527d-4dab-a5b3-21197faccd05'

Author = 'abgox'
Author = 'abgox'

Copyright = '(c) abgox. All rights reserved.'
Copyright = '(c) abgox. All rights reserved.'

Description = 'A completion manager for better and simpler use powershell completions. For more information, please visit the project: https://github.com/abgox/PSCompletions | https://gitee.com/abgox/PSCompletions'
ScriptsToProcess = 'core\init.ps1'
Description = 'A completion manager for better and simpler use powershell completions. For more information, please visit the project or website: https://github.com/abgox/PSCompletions | https://gitee.com/abgox/PSCompletions | https://pscompletions.pages.dev'
ScriptsToProcess = 'core\init.ps1'

FunctionsToExport = 'PSCompletions'

PrivateData = @{
PrivateData = @{

PSData = @{

Tags = @('PowerShell', 'pwsh', 'Tab', 'PS-Completions', 'Dynamic', 'Multi-language', 'base-in-json' , 'Completion-Manager')
Tags = @('PowerShell', 'pwsh', 'Tab', 'PS-Completions', 'Dynamic', 'Multi-language', 'base-in-json' , 'Completion-Manager', 'TabExpansion2')

LicenseUri = 'https://github.com/abgox/PSCompletions/blob/main/LICENSE'

Expand Down
26 changes: 17 additions & 9 deletions module/PSCompletions.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function PSCompletions {
Set-Item -Path Function:$($PSCompletions.config.function_name) -Value {
$arg = $args

# ? 由于此处使用 $PSCompletions.replace_content 会导致其无法使用外部变量,所以重新定义一个函数以供使用
Expand Down Expand Up @@ -252,10 +252,8 @@
return
}
foreach ($alias in $arg[3..($arg.Length - 1)]) {
if ($alias -like "* *") {
$alias = ($alias -split ' ')[0]
}
if ($alias -in (Get-Alias).Name -or $alias -in (Get-Command).Name) {
$alias = ($alias -split ' ')[0]
if (Get-Command $alias -ErrorAction SilentlyContinue) {
Show-ParamError 'err' '' $PSCompletions.info.alias.add.err.cmd_exist
return
}
Expand Down Expand Up @@ -308,7 +306,7 @@
}
}
function _config {
$cmd_list = @('language', 'disable_cache', 'update', 'module_update', 'symbol', 'github', 'gitee', 'url')
$cmd_list = @('language', 'disable_cache', 'update', 'module_update', 'symbol', 'github', 'gitee', 'url', 'function_name')
if ($arg.Length -lt 2) {
Show-ParamError 'min' '' $PSCompletions.info.sub_cmd $PSCompletions.info.config.example
return
Expand Down Expand Up @@ -353,7 +351,7 @@
$config_item = $arg[1]
switch ($arg[1]) {
'language' {
handle_done $true
handle_done ($arg[2] -is [string] -and $arg[2] -ne '')
}
'disable_cache' {
handle_done ($arg[2] -is [int] -and $arg[2] -in @(1, 0)) -common_err
Expand All @@ -373,6 +371,15 @@
'url' {
handle_done ($arg[2] -match 'http[s]?://' -or $arg[2] -eq '')
}
'function_name' {
# Get-Command PSCompletions 会导致触发更新,需要特殊处理
if ($arg[2] -eq 'PSCompletions' -and $PSCompletions.config.function_name -ne 'PSCompletions') {
handle_done $true
return
}
$is_exist = Get-Command $arg[2] -ErrorAction SilentlyContinue
handle_done ($arg[2] -is [string] -and $arg[2] -ne '' -and !$is_exist)
}
}
}
function _completion {
Expand Down Expand Up @@ -451,7 +458,6 @@
Out-Config
$PSCompletions.write_with_color((_replace $PSCompletions.info.completion.done))
}

function _menu {
$cmd_list = @('symbol', 'line_theme', 'color_theme', 'custom', 'config')
if ($arg.Length -lt 2) {
Expand Down Expand Up @@ -933,4 +939,6 @@
}
}
if ($need_init) { $PSCompletions.init_data() }
}
} -Option ReadOnly

Export-ModuleMember -Function $PSCompletions.config.function_name
Loading

0 comments on commit 43033d5

Please sign in to comment.