Skip to content

Commit

Permalink
feat(completions): update hooks of git scoop wsl
Browse files Browse the repository at this point in the history
- Replace ForEach-Object with foreach to avoid some problems
  • Loading branch information
abgox committed Jun 8, 2024
1 parent 8519e4a commit b9fe424
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion completions/git/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e7fde21f-b4a9-4dc2-971d-c7aac14a8a0e
2f60b789-4e63-4d7e-945a-17d7de3e9f2d
18 changes: 9 additions & 9 deletions completions/git/hooks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
ORIG_HEAD = (git show ORIG_HEAD --relative-date -q 2>$null) -join "`n"
MERGE_HEAD = (git show MERGE_HEAD --relative-date -q 2>$null) -join "`n"
}
@('HEAD', 'FETCH_HEAD', 'ORIG_HEAD', 'MERGE_HEAD') | ForEach-Object {
foreach ($_ in @('HEAD', 'FETCH_HEAD', 'ORIG_HEAD', 'MERGE_HEAD')) {
if (!$head_list.$_) {
$head_list.Remove($_)
}
Expand All @@ -26,8 +26,8 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
if ($PSCompletions.config.comp_config.git.max_commit -in @('', $null)) {
$PSCompletions.config.comp_config.git.max_commit = 20
}

git log --pretty='format:%h%nDate: %cr%nAuthor: %an <%ae>%n%B%n@@@--------------------@@@' -n $PSCompletions.config.comp_config.git.max_commit --encoding=gbk 2>$null | ForEach-Object {
$git_info = git log --pretty='format:%h%nDate: %cr%nAuthor: %an <%ae>%n%B%n@@@--------------------@@@' -n $PSCompletions.config.comp_config.git.max_commit --encoding=gbk 2>$null
foreach ($_ in $git_info) {
if ($_ -ne '@@@--------------------@@@') {
$current_commit.Add($_)
}
Expand All @@ -39,14 +39,14 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
$current_commit = $null
$tag_list = git tag 2>$null

$branch_list | ForEach-Object {
foreach ($_ in $branch_list) {
$info = 'branch --- ' + $_

addCompletion "switch $($_)" '' $info
addCompletion "merge $($_)" '' $info
addCompletion "diff $($_)" '' $info
}
$head_list.Keys | ForEach-Object {
foreach ($_ in $head_list.Keys) {
$info = $head_list.$_
addCompletion "rebase -i $($_)" '' $info
addCompletion "rebase --interactive $($_)" '' $info
Expand All @@ -57,11 +57,11 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
addCompletion "reset --mixed $($_)" '' $info
addCompletion "show $($_)" '' $info
}
$branch_head_list | ForEach-Object {
foreach ($_ in $branch_head_list) {
$info = if ($head_list.$_) { $head_list.$_ }else { 'branch --- ' + $_ }
addCompletion "checkout $($_)" '' $info
}
$remote_list | ForEach-Object {
foreach($_ in $remote_list) {
$info = 'remote --- ' + $_
addCompletion "push $($_)" '' $info

Expand All @@ -70,7 +70,7 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
addCompletion "remote rename $($_)" '' $info
addCompletion "remote rm $($_)" '' $info
}
$commit_info | ForEach-Object {
foreach($_ in $commit_info) {
$hash = $_[0]
$date = $_[1]
$author = $_[2]
Expand All @@ -90,7 +90,7 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
addCompletion "revert $($hash)" '' $content
addCompletion "commit $($hash)" '' $content
}
$tag_list | ForEach-Object {
foreach($_ in $tag_list) {
addCompletion "tag -d $($_)" '' "tag --- $($_)"
addCompletion "tag -v $($_)" '' "tag --- $($_)"
}
Expand Down
2 changes: 1 addition & 1 deletion completions/scoop/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bdfdc8d1-1bf5-40b3-8f60-0b8e82919c0e
43493e30-96b2-49c1-8012-fa249006930b
8 changes: 4 additions & 4 deletions completions/scoop/hooks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
if ($path) { [environment]::SetEnvironmentvariable('SCOOP_GLOBAL', $path, 'User') }
$scoop_global_path = $path
}
scoop bucket known | ForEach-Object {
foreach ($_ in scoop bucket known) {
$bucket = $_
addCompletion "bucket add $($bucket)" '' $PSCompletions.replace_content($PSCompletions.data.scoop.info.tip.bucket.add)
}
Get-ChildItem "$scoop_path\buckets" 2>$null | ForEach-Object {
foreach ($_ in Get-ChildItem "$scoop_path\buckets" 2>$null) {
$bucket = $_.Name
addCompletion "bucket rm $($bucket)" '' $PSCompletions.replace_content($PSCompletions.data.scoop.info.tip.bucket.rm)
}
@("$scoop_path\apps", "$scoop_global_path\apps") | ForEach-Object {
foreach ($_ in @("$scoop_path\apps", "$scoop_global_path\apps")) {
foreach ($item in (Get-ChildItem $_ 2>$null)) {
$app = $item.Name
$path = $item.FullName
Expand All @@ -47,7 +47,7 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
addCompletion "prefix $($app)" '' $PSCompletions.replace_content($PSCompletions.data.scoop.info.tip.prefix)
}
}
Get-ChildItem "$scoop_path\cache" | ForEach-Object {
foreach ($_ in Get-ChildItem "$scoop_path\cache" -ErrorAction SilentlyContinue) {
$match = $_.BaseName -match '^([^#]+#[^#]+)'
if ($match) {
$part = $_.Name -split "#"
Expand Down
2 changes: 1 addition & 1 deletion completions/wsl/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aea4440d-924d-46f6-8106-9fe16af67df8
c100324b-5b60-47f5-b678-102fc5b7a1ab
31 changes: 16 additions & 15 deletions completions/wsl/hooks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
}
function CleanNul($data) {
$res = [System.Collections.Generic.List[byte]]::new()
[System.Text.Encoding]::UTF8.GetBytes($data) | ForEach-Object {
foreach ($_ in [System.Text.Encoding]::UTF8.GetBytes($data)) {
# Remove NUL(0x00) characters from binary data
if ($_ -ne 0x00) { $res.add($_) }
}
return [System.Text.Encoding]::UTF8.GetString($res)
}

$Distro_list = wsl -l -q | ForEach-Object { CleanNul $_ } | Where-Object { $_ -ne '' }
$Distro_list | ForEach-Object {
$Distro = $_
addCompletion "~ -d $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "-d $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "~ --distribution $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "--distribution $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
$Distro_list = foreach ($_ in wsl -l -q) { CleanNul $_ }
foreach ($_ in $Distro_list) {
if ($_ -ne '') {
$Distro = $_
addCompletion "~ -d $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "-d $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "~ --distribution $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "--distribution $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')

addCompletion "-s $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "--set-default $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--set-default')
addCompletion "-s $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--distribution')
addCompletion "--set-default $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--set-default')

addCompletion "-t $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--set-default')
addCompletion "--terminate $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--terminate')
addCompletion "-t $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--set-default')
addCompletion "--terminate $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--terminate')

addCompletion "--unregister $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--unregister')

addCompletion "--unregister $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--unregister')

addCompletion "--export $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--export')
addCompletion "--export $($Distro)" '' $PSCompletions.replace_content($PSCompletions.data.wsl.info.tip.'--export')
}
}
return $completions
}

0 comments on commit b9fe424

Please sign in to comment.