Skip to content

Commit

Permalink
Merge pull request #36 from abgox/module
Browse files Browse the repository at this point in the history
feat(module): update version to 5.0.5
  • Loading branch information
abgox authored Sep 2, 2024
2 parents 01a46db + 0e6041b commit 419bdab
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 40 deletions.
5 changes: 5 additions & 0 deletions module/CHANGELOG-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<a href="./CHANGELOG-CN.md">简体中文</a>
</p>

## 5.0.5 (2024/9/2)

-`$PSCompletions` 中添加一个方法 `return_completion` 用于 `hooks.ps1`
- 其他的优化和修复。

## 5.0.4 (2024/9/1)

- 修复 `psc rm *` 命令会重置所有配置项的问题。
Expand Down
15 changes: 15 additions & 0 deletions module/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
[
{
"version": "5.0.5",
"info": {
"zh-CN": [
"修复(2024/9/2)\n",
"- 在 <@Magenta>$PSCompletions<@Blue> 中添加一个方法 <@Magenta>return_completion<@Blue> 用于 hooks.ps1\n",
"- 其他的优化和修复。\n"
],
"en-US": [
"Fix(2024/9/2)\n",
"- Add a method <@Magenta>return_completion<@Blue> in <@Magenta>$PSCompletions<@Blue> for hooks.ps1.\n",
"- Other optimizations and fixes.\n"
]
}
},
{
"version": "5.0.4",
"info": {
Expand Down
5 changes: 5 additions & 0 deletions module/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<a href="./CHANGELOG.md">English</a>
</p>

## 5.0.5 (2024/9/2)

- Add a method `return_completion` in `$PSCompletions` for `hooks.ps1`.
- Other optimizations and fixes.

## 5.0.4 (2024/9/1)

- Fix the issue that the `psc rm *` command will reset all configuration items.
Expand Down
2 changes: 1 addition & 1 deletion module/PSCompletions/PSCompletions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@{
RootModule = 'PSCompletions.psm1'

ModuleVersion = '5.0.4'
ModuleVersion = '5.0.5'

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

Expand Down
8 changes: 1 addition & 7 deletions module/PSCompletions/PSCompletions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,7 @@
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)
handle_done ($arg[2] -ne '' -and !(Get-Command $arg[2] -ErrorAction SilentlyContinue))
}
}
}
Expand Down
70 changes: 39 additions & 31 deletions module/PSCompletions/core/init.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using namespace System.Management.Automation
$_ = Split-Path $PSScriptRoot -Parent
New-Variable -Name PSCompletions -Value @{
version = '5.0.4'
version = '5.0.5'
path = @{
root = $_
completions = Join-Path $_ 'completions'
Expand Down Expand Up @@ -107,8 +107,19 @@ else {
. $PSScriptRoot\menu\win.ps1
}

Add-Member -InputObject $PSCompletions -MemberType ScriptMethod return_completion {
param([string]$name, [string]$tip = ' ', [array]$symbols)
$_symbol = foreach ($c in $symbols) { $PSCompletions.config.$c }
$padSymbols = if ($_symbol) { "$($PSCompletions.config.between_item_and_symbol)$($_symbol -join '')" }else { '' }
$cmd_arr = $name -split ' '
@{
name = $name
ListItemText = "$($cmd_arr[-1])$($padSymbols)"
CompletionText = $cmd_arr[-1]
ToolTip = $tip
}
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod get_completion {
# 获取 json 数据
if ($PSCompletions.job.State -eq 'Completed') {
$PSCompletions.completions = Receive-Job $PSCompletions.job
Remove-Job $PSCompletions.job
Expand Down Expand Up @@ -568,21 +579,10 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod split_array {
}
$chunks
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod ensure_file {
param([string]$path)
if (!(Test-Path $path)) { New-Item -ItemType File $path > $null }
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod ensure_dir {
param([string]$path)
if (!(Test-Path $path)) { New-Item -ItemType Directory $path > $null }
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod join_path {
$res = $args[0]
for ($i = 1; $i -lt $args.Count; $i++) {
$res = Join-Path $res $args[$i]
}
$res
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod get_language {
param ([string]$completion)
$path_config = "$($PSCompletions.path.completions)/$completion/config.json"
Expand Down Expand Up @@ -839,7 +839,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod download_file {
Write-Host "File save path: $file" -ForegroundColor Red
Write-Host "If you are sure that it is not a network problem, please submit an issue`n" -ForegroundColor Red
}
throw
throw $_
}
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod add_completion {
Expand All @@ -853,10 +853,11 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod add_completion {
$is_update = (Test-Path "$($PSCompletions.path.completions)/$completion") -and $is_update

$completion_dir = Join-Path $PSCompletions.path.completions $completion
$language_dir = Join-Path $completion_dir 'language'

$PSCompletions.ensure_dir($PSCompletions.path.completions)
$PSCompletions.ensure_dir($completion_dir)
$PSCompletions.ensure_dir((Join-Path $completion_dir 'language'))
$PSCompletions.ensure_dir($language_dir)

$download_info = @{
url = "$url/config.json"
Expand All @@ -875,7 +876,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod add_completion {
foreach ($_ in $config.language) {
$files += @{
Uri = "$url/language/$_.json"
OutFile = $PSCompletions.join_path($completion_dir, 'language', "$_.json")
OutFile = Join-Path $language_dir "$_.json"
}
}
if ($config.hooks) {
Expand Down Expand Up @@ -1081,7 +1082,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_powers

if (!(Test-Path (Join-Path $PSCompletions.path.core '.temp'))) {
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod move_old_version {
$version = (Get-ChildItem (Split-Path $PSCompletions.path.root -Parent) -ErrorAction SilentlyContinue).Name | Sort-Object { [Version]$_ } -ErrorAction SilentlyContinue
$version = (Get-ChildItem (Split-Path $PSCompletions.path.root -Parent) -ErrorAction SilentlyContinue).Name | Sort-Object { [Version]$_ } -ErrorAction SilentlyContinue | Where-Object { $_ -match '^\d+\.\d.*' }
if ($version -is [array]) {
$old_version = $version[-2]
if ($old_version -match '^\d+\.\d.*' -and $old_version -ge '4') {
Expand Down Expand Up @@ -1206,7 +1207,20 @@ if (!(Test-Path (Join-Path $PSCompletions.path.core '.temp'))) {
}
}
else {
$PSCompletions.is_first_init = $true
if ($PSUICulture -eq 'zh-CN') {
$language = 'zh-CN'
$PSCompletions.url = 'https://gitee.com/abgox/PSCompletions/raw/main'
}
else {
$language = 'en-US'
$PSCompletions.url = 'https://raw.githubusercontent.com/abgox/PSCompletions/main'
}

$PSCompletions.ensure_dir("$($PSCompletions.path.completions)/psc/language")
$PSCompletions.download_file("$($PSCompletions.url)/completions/psc/language/$language.json", "$($PSCompletions.path.completions)/psc/language/$language.json")

$PSCompletions.info = $PSCompletions.ConvertFrom_JsonToHashtable($PSCompletions.get_raw_content("$($PSCompletions.path.completions)/psc/language/$language.json")).info
$PSCompletions.write_with_color($PSCompletions.replace_content($PSCompletions.info.init_info))
}
}
$PSCompletions.move_old_version()
Expand All @@ -1215,29 +1229,23 @@ if (!(Test-Path (Join-Path $PSCompletions.path.core '.temp'))) {

$PSCompletions.init_data()

if (Get-Command Set-PSReadLineKeyHandler -ErrorAction SilentlyContinue) {
Set-PSReadLineKeyHandler $PSCompletions.config.trigger_key MenuComplete
$PSCompletions.generate_completion()
$PSCompletions.handle_completion()
}

if ($PSCompletions.is_first_init) {
$PSCompletions.write_with_color($PSCompletions.replace_content($PSCompletions.info.init_info))
}
Set-PSReadLineKeyHandler $PSCompletions.config.trigger_key MenuComplete
$PSCompletions.generate_completion()
$PSCompletions.handle_completion()

foreach ($_ in $PSCompletions.data.aliasMap.Keys) {
if ($PSCompletions.data.aliasMap.$_ -eq 'psc') {
Set-Alias $_ $PSCompletions.config.function_name -ErrorAction SilentlyContinue
Set-Alias $_ $PSCompletions.config.function_name
}
else {
if ($_ -ne $PSCompletions.data.aliasMap.$_) {
Set-Alias $_ $PSCompletions.data.aliasMap.$_ -ErrorAction SilentlyContinue
Set-Alias $_ $PSCompletions.data.aliasMap.$_
}
}
}

if ($PSCompletions.config.enable_module_update -match '^\d+\.\d.*') {
$PSCompletions.version_list = $PSCompletions.config.enable_module_update, $PSCompletions.version | Sort-Object { [version] $_ } -Descending
if ($PSCompletions.config.enable_module_update -notin @(0, 1)) {
$PSCompletions.version_list = $PSCompletions.config.enable_module_update, $PSCompletions.version | Sort-Object { [version] $_ } -Descending -ErrorAction SilentlyContinue
if ($PSCompletions.version_list[0] -ne $PSCompletions.version) {
$PSCompletions.wc.DownloadFile("$($PSCompletions.url)/module/CHANGELOG.json", (Join-Path $PSCompletions.path.core 'CHANGELOG.json'))
$null = $PSCompletions.confirm_do($PSCompletions.info.module.update, {
Expand Down
2 changes: 1 addition & 1 deletion module/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.4
5.0.5

0 comments on commit 419bdab

Please sign in to comment.