Skip to content

Commit

Permalink
fix(completions): update all hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
abgox committed Nov 15, 2024
1 parent c522978 commit 8f398d8
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 208 deletions.
2 changes: 1 addition & 1 deletion completions/git/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
211219ea-a694-4b13-bfa0-d772081d727a
ce23c252-fb81-4662-8cf9-f0ee3f1dac35
84 changes: 36 additions & 48 deletions completions/git/hooks.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
function handleCompletions($completions) {
$tempList = @()
function returnCompletion($name, $tip = ' ', $symbol = '') {
$symbols = foreach ($c in ($symbol -split ' ')) { $PSCompletions.config.$c }
$symbols = $symbols -join ''
$padSymbols = if ($symbols) { "$($PSCompletions.config.between_item_and_symbol)$($symbols)" }else { '' }
$cmd_arr = $name -split ' '

@{
name = $name
ListItemText = "$($cmd_arr[-1])$($padSymbols)"
CompletionText = $cmd_arr[-1]
ToolTip = $tip
}
}
$branch_list = git branch --format='%(refname:lstrip=2)' 2>$null
$head_list = @{
HEAD = (git show HEAD --relative-date -q 2>$null) -join "`n"
Expand Down Expand Up @@ -48,33 +36,33 @@

foreach ($_ in $branch_list) {
$info = 'branch --- ' + $_
$tempList += returnCompletion "switch $($_)" $info
$tempList += returnCompletion "branch $($_)" $info
$tempList += returnCompletion "merge $($_)" $info
$tempList += returnCompletion "diff $($_)" $info
$tempList += $PSCompletions.return_completion("switch $($_)", $info)
$tempList += $PSCompletions.return_completion("branch $($_)", $info)
$tempList += $PSCompletions.return_completion("merge $($_)", $info)
$tempList += $PSCompletions.return_completion("diff $($_)", $info)
}
foreach ($_ in $head_list.Keys) {
$info = $head_list.$_
$tempList += returnCompletion "rebase -i $($_)" $info
$tempList += returnCompletion "rebase --interactive $($_)" $info
$tempList += returnCompletion "diff $($_)" $info
$tempList += returnCompletion "reset $($_)" $info
$tempList += returnCompletion "reset --soft $($_)" $info
$tempList += returnCompletion "reset --hard $($_)" $info
$tempList += returnCompletion "reset --mixed $($_)" $info
$tempList += returnCompletion "show $($_)" $info
$tempList += $PSCompletions.return_completion("rebase -i $($_)", $info)
$tempList += $PSCompletions.return_completion("rebase --interactive $($_)", $info)
$tempList += $PSCompletions.return_completion("diff $($_)", $info)
$tempList += $PSCompletions.return_completion("reset $($_)", $info)
$tempList += $PSCompletions.return_completion("reset --soft $($_)", $info)
$tempList += $PSCompletions.return_completion("reset --hard $($_)", $info)
$tempList += $PSCompletions.return_completion("reset --mixed $($_)", $info)
$tempList += $PSCompletions.return_completion("show $($_)", $info)
}
foreach ($_ in $branch_head_list) {
$info = if ($head_list.$_) { $head_list.$_ }else { 'branch --- ' + $_ }
$tempList += returnCompletion "checkout $($_)" $info
$tempList += $PSCompletions.return_completion("checkout $($_)", $info)
}
foreach ($_ in $remote_list) {
$info = 'remote --- ' + $_
$tempList += returnCompletion "push $($_)" $info
$tempList += returnCompletion "pull $($_)" $info
$tempList += returnCompletion "fetch $($_)" $info
$tempList += returnCompletion "remote rename $($_)" $info
$tempList += returnCompletion "remote rm $($_)" $info
$tempList += $PSCompletions.return_completion("push $($_)", $info)
$tempList += $PSCompletions.return_completion("pull $($_)", $info)
$tempList += $PSCompletions.return_completion("fetch $($_)", $info)
$tempList += $PSCompletions.return_completion("remote rename $($_)", $info)
$tempList += $PSCompletions.return_completion("remote rm $($_)", $info)
}
foreach ($_ in $commit_info) {
$hash = $_[0]
Expand All @@ -83,30 +71,30 @@
$commit = $_[3..($_.Length - 1)]
$content = $date + "`n" + $author + "`n" + ($commit -join "`n")

$tempList += returnCompletion "commit -C $($hash)" $content
$tempList += returnCompletion "rebase -i $($hash)" $content
$tempList += returnCompletion "rebase --interactive $($hash)" $content
$tempList += returnCompletion "checkout $($hash)" $content
$tempList += returnCompletion "diff $($hash)" $content
$tempList += returnCompletion "reset $($hash)" $content
$tempList += returnCompletion "reset --soft $($hash)" $content
$tempList += returnCompletion "reset --hard $($hash)" $content
$tempList += returnCompletion "reset --mixed $($hash)" $content
$tempList += returnCompletion "show $($hash)" $content
$tempList += returnCompletion "revert $($hash)" $content
$tempList += returnCompletion "commit $($hash)" $content
$tempList += $PSCompletions.return_completion("commit -C $($hash)", $content)
$tempList += $PSCompletions.return_completion("rebase -i $($hash)", $content)
$tempList += $PSCompletions.return_completion("rebase --interactive $($hash)", $content)
$tempList += $PSCompletions.return_completion("checkout $($hash)", $content)
$tempList += $PSCompletions.return_completion("diff $($hash)", $content)
$tempList += $PSCompletions.return_completion("reset $($hash)", $content)
$tempList += $PSCompletions.return_completion("reset --soft $($hash)", $content)
$tempList += $PSCompletions.return_completion("reset --hard $($hash)", $content)
$tempList += $PSCompletions.return_completion("reset --mixed $($hash)", $content)
$tempList += $PSCompletions.return_completion("show $($hash)", $content)
$tempList += $PSCompletions.return_completion("revert $($hash)", $content)
$tempList += $PSCompletions.return_completion("commit $($hash)", $content)
}
foreach ($_ in $tag_list) {
$tempList += returnCompletion "tag -d $($_)" "tag --- $($_)"
$tempList += returnCompletion "tag -v $($_)" "tag --- $($_)"
$tempList += $PSCompletions.return_completion("tag -d $($_)", "tag --- $($_)")
$tempList += $PSCompletions.return_completion("tag -v $($_)", "tag --- $($_)")
}
foreach ($_ in git stash list --encoding=gbk 2>$null) {
if ($_ -match 'stash@\{(\d+)\}') {
$stashId = $matches[1]
$tempList += returnCompletion "stash show $stashId" $_
$tempList += returnCompletion "stash pop $stashId" $_
$tempList += returnCompletion "stash apply $stashId" $_
$tempList += returnCompletion "stash drop $stashId" $_
$tempList += $PSCompletions.return_completion("stash show $stashId", $_)
$tempList += $PSCompletions.return_completion("stash pop $stashId", $_)
$tempList += $PSCompletions.return_completion("stash apply $stashId", $_)
$tempList += $PSCompletions.return_completion("stash drop $stashId", $_)
}
}
return $tempList + $completions
Expand Down
2 changes: 1 addition & 1 deletion completions/npm/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
abbbb6bb-8d49-42ef-a6db-5955ea851a82
5ccd47af-196e-4008-ac4f-46686c388c6a
23 changes: 5 additions & 18 deletions completions/npm/hooks.ps1
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
function handleCompletions($completions) {
if (!(Test-Path "package.json")) { return $completions }
$tempList = @()
function returnCompletion($name, $tip = ' ', $symbol = '') {
$symbols = foreach ($c in ($symbol -split ' ')) { $PSCompletions.config.$c }
$symbols = $symbols -join ''
$padSymbols = if ($symbols) { "$($PSCompletions.config.between_item_and_symbol)$($symbols)" }else { '' }
$cmd_arr = $name -split ' '

@{
name = $name
ListItemText = "$($cmd_arr[-1])$($padSymbols)"
CompletionText = $cmd_arr[-1]
ToolTip = $tip
}
}

$packageJson = $PSCompletions.ConvertFrom_JsonToHashtable((Get-Content "package.json" -Raw))
$scripts = $packageJson.scripts
$dependencies = $packageJson.dependencies
$devDependencies = $packageJson.devDependencies
if ($scripts) {
foreach ($script in $scripts.Keys) {
$tempList += returnCompletion "run $script" "package.json scripts:`n$($scripts.$script)"
$tempList += $PSCompletions.return_completion("run $script", "package.json scripts:`n$($scripts.$script)")
}
}
if ($dependencies) {
foreach ($dependency in $dependencies.Keys) {
$tempList += returnCompletion "uninstall $dependency" "Uninstall dependency: $($dependency) ($($dependencies.$dependency))"
$tempList += returnCompletion "update $dependency" "Current Version: $($dependencies.$dependency)"
$tempList += $PSCompletions.return_completion("uninstall $dependency", "Uninstall dependency: $($dependency) ($($dependencies.$dependency))")
$tempList += $PSCompletions.return_completion("update $dependency", "Current Version: $($dependencies.$dependency)")
}
}
if ($devDependencies) {
foreach ($devDependency in $devDependencies.Keys) {
$tempList += returnCompletion "uninstall $devDependency" "Uninstall devDependency: $($devDependency) ($($devDependencies.$devDependency))"
$tempList += returnCompletion "update $devDependency" "Current Version: $($devDependencies.$devDependency)"
$tempList += $PSCompletions.return_completion("uninstall $devDependency", "Uninstall devDependency: $($devDependency) ($($devDependencies.$devDependency))")
$tempList += $PSCompletions.return_completion("update $devDependency", "Current Version: $($devDependencies.$devDependency)")
}
}
return $tempList + $completions
Expand Down
2 changes: 1 addition & 1 deletion completions/pnpm/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c67113d3-c1d3-4b1f-bae3-a9a18e0daa82
ce31e48b-522a-4c05-b3c5-e60b1ce4b62f
35 changes: 11 additions & 24 deletions completions/pnpm/hooks.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
function handleCompletions($completions) {
if (!(Test-Path "package.json")) { return $completions }
$tempList = @()
function returnCompletion($name, $tip = ' ', $symbol = '') {
$symbols = foreach ($c in ($symbol -split ' ')) { $PSCompletions.config.$c }
$symbols = $symbols -join ''
$padSymbols = if ($symbols) { "$($PSCompletions.config.between_item_and_symbol)$($symbols)" }else { '' }
$cmd_arr = $name -split ' '

@{
name = $name
ListItemText = "$($cmd_arr[-1])$($padSymbols)"
CompletionText = $cmd_arr[-1]
ToolTip = $tip
}
}

$packageJson = $PSCompletions.ConvertFrom_JsonToHashtable((Get-Content "package.json" -Raw))
$scripts = $packageJson.scripts
$dependencies = $packageJson.dependencies
$devDependencies = $packageJson.devDependencies
if ($scripts) {
foreach ($script in $scripts.Keys) {
$tempList += returnCompletion "run $script" "package.json scripts:`n$($scripts.$script)"
$tempList += $PSCompletions.return_completion("run $script", "package.json scripts:`n$($scripts.$script)")
}
}
if ($dependencies) {
foreach ($dependency in $dependencies.Keys) {
$tempList += returnCompletion "rm $dependency" "Remove dependency: $($dependency) ($($dependencies.$dependency))"
$tempList += returnCompletion "remove $dependency" "Remove dependency: $($dependency) ($($dependencies.$dependency))"
$tempList += $PSCompletions.return_completion("rm $dependency", "Remove dependency: $($dependency) ($($dependencies.$dependency))")
$tempList += $PSCompletions.return_completion("remove $dependency", "Remove dependency: $($dependency) ($($dependencies.$dependency))")

$tempList += returnCompletion "update $dependency" "Current Version: $($dependencies.$dependency)"
$tempList += returnCompletion "up $dependency" "Current Version: $($dependencies.$dependency)"
$tempList += returnCompletion "upgrade $dependency" "Current Version: $($dependencies.$dependency)"
$tempList += $PSCompletions.return_completion("update $dependency", "Current Version: $($dependencies.$dependency)")
$tempList += $PSCompletions.return_completion("up $dependency", "Current Version: $($dependencies.$dependency)")
$tempList += $PSCompletions.return_completion("upgrade $dependency", "Current Version: $($dependencies.$dependency)")
}
}
if ($devDependencies) {
foreach ($devDependency in $devDependencies.Keys) {
$tempList += returnCompletion "rm $devDependency" "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))"
$tempList += returnCompletion "remove $devDependency" "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))"
$tempList += $PSCompletions.return_completion("rm $devDependency", "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))")
$tempList += $PSCompletions.return_completion("remove $devDependency", "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))")

$tempList += returnCompletion "update $devDependency" "Current Version: $($devDependencies.$devDependency)"
$tempList += returnCompletion "up $devDependency" "Current Version: $($devDependencies.$devDependency)"
$tempList += returnCompletion "upgrade $devDependency" "Current Version: $($devDependencies.$devDependency)"
$tempList += $PSCompletions.return_completion("update $devDependency", "Current Version: $($devDependencies.$devDependency)")
$tempList += $PSCompletions.return_completion("up $devDependency", "Current Version: $($devDependencies.$devDependency)")
$tempList += $PSCompletions.return_completion("upgrade $devDependency", "Current Version: $($devDependencies.$devDependency)")
}
}
return $tempList + $completions
Expand Down
2 changes: 1 addition & 1 deletion completions/psc/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
afb85eed-c01f-4117-81c6-8b4751e0f1cd
6b969328-ef06-44c4-b863-c3bb10aab7c7
Loading

0 comments on commit 8f398d8

Please sign in to comment.