Skip to content

Commit

Permalink
feat(completions): update
Browse files Browse the repository at this point in the history
  • Loading branch information
abgox committed Aug 14, 2024
1 parent a5e8c05 commit 38e2e5d
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 189 deletions.
2 changes: 1 addition & 1 deletion completions/git/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bed7a5be-afde-4726-adb4-4542ebaa9a95
a7339dd8-1703-493b-afba-3cd3c17b6e03
102 changes: 51 additions & 51 deletions completions/git/hooks.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function handleCompletions([System.Collections.Generic.List[System.Object]]$completions) {
$tempList = [System.Collections.Generic.List[System.Object]]@()
function addCompletion($name, $tip = ' ', $symbol = '') {
function handleCompletions($completions) {
$tempList = @()
function returnCompletion($name, $tip = ' ', $symbol = '') {
$symbols = foreach ($c in ($symbol -split ' ')) { $PSCompletions.config."symbol_$($c)" }
$symbols = $symbols -join ''
$padSymbols = if ($symbols) { "$($PSCompletions.config.menu_between_item_and_symbol)$($symbols)" }else { '' }
$cmd_arr = $name -split ' '

$tempList.Add(@{
name = $name
ListItemText = "$($cmd_arr[-1])$($padSymbols)"
CompletionText = $cmd_arr[-1]
ToolTip = $tip
})
@{
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 = @{
Expand All @@ -28,53 +28,53 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
$branch_head_list = $branch_list + $head_list.Keys
$remote_list = git remote 2>$null
$commit_info = [System.Collections.Generic.List[array]]::new()
$current_commit = [System.Collections.Generic.List[string]]::new()
if ($PSCompletions.config.comp_config.git.max_commit -in @('', $null)) {
$PSCompletions.config.comp_config.git.max_commit = 20
}
$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
$guid = [guid]::NewGuid().Guid
$git_info = git log --pretty="format:%h%nDate: %cr%nAuthor: %an <%ae>%n%B%n$($guid)" -n $PSCompletions.config.comp_config.git.max_commit --encoding=gbk 2>$null
$current_commit = @()
foreach ($_ in $git_info) {
if ($_ -ne '@@@--------------------@@@') {
$current_commit.Add($_)
if ($_ -ne $guid) {
$current_commit += $_
}
else {
$commit_info.add($current_commit)
$current_commit = [System.Collections.Generic.List[string]]::new()
$current_commit = @()
}
}
$current_commit = $null
$tag_list = git tag 2>$null

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

addCompletion "switch $($_)" $info
addCompletion "merge $($_)" $info
addCompletion "diff $($_)" $info
$tempList += returnCompletion "switch $($_)" $info
$tempList += returnCompletion "branch $($_)" $info
$tempList += returnCompletion "merge $($_)" $info
$tempList += returnCompletion "diff $($_)" $info
}
foreach ($_ in $head_list.Keys) {
$info = $head_list.$_
addCompletion "rebase -i $($_)" $info
addCompletion "rebase --interactive $($_)" $info
addCompletion "diff $($_)" $info
addCompletion "reset $($_)" $info
addCompletion "reset --soft $($_)" $info
addCompletion "reset --hard $($_)" $info
addCompletion "reset --mixed $($_)" $info
addCompletion "show $($_)" $info
$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
}
foreach ($_ in $branch_head_list) {
$info = if ($head_list.$_) { $head_list.$_ }else { 'branch --- ' + $_ }
addCompletion "checkout $($_)" $info
$tempList += returnCompletion "checkout $($_)" $info
}
foreach ($_ in $remote_list) {
$info = 'remote --- ' + $_
addCompletion "push $($_)" $info

addCompletion "pull $($_)" $info
addCompletion "fetch $($_)" $info
addCompletion "remote rename $($_)" $info
addCompletion "remote rm $($_)" $info
$tempList += returnCompletion "push $($_)" $info
$tempList += returnCompletion "pull $($_)" $info
$tempList += returnCompletion "fetch $($_)" $info
$tempList += returnCompletion "remote rename $($_)" $info
$tempList += returnCompletion "remote rm $($_)" $info
}
foreach ($_ in $commit_info) {
$hash = $_[0]
Expand All @@ -83,30 +83,30 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
$commit = $_[3..($_.Length - 1)]
$content = $date + "`n" + $author + "`n" + ($commit -join "`n")

addCompletion "commit -C $($hash)" $content
addCompletion "rebase -i $($hash)" $content
addCompletion "rebase --interactive $($hash)" $content
addCompletion "checkout $($hash)" $content
addCompletion "diff $($hash)" $content
addCompletion "reset $($hash)" $content
addCompletion "reset --soft $($hash)" $content
addCompletion "reset --hard $($hash)" $content
addCompletion "reset --mixed $($hash)" $content
addCompletion "show $($hash)" $content
addCompletion "revert $($hash)" $content
addCompletion "commit $($hash)" $content
$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
}
foreach ($_ in $tag_list) {
addCompletion "tag -d $($_)" "tag --- $($_)"
addCompletion "tag -v $($_)" "tag --- $($_)"
$tempList += returnCompletion "tag -d $($_)" "tag --- $($_)"
$tempList += returnCompletion "tag -v $($_)" "tag --- $($_)"
}
foreach ($_ in git stash list --encoding=gbk 2>$null) {
if ($_ -match 'stash@\{(\d+)\}') {
$stashId = $matches[1]
addCompletion "stash show $stashId" $_
addCompletion "stash pop $stashId" $_
addCompletion "stash apply $stashId" $_
addCompletion "stash drop $stashId" $_
$tempList += returnCompletion "stash show $stashId" $_
$tempList += returnCompletion "stash pop $stashId" $_
$tempList += returnCompletion "stash apply $stashId" $_
$tempList += returnCompletion "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 @@
3423b6ac-24b2-4e8f-9fbb-964ea7ade1f8
277f9e8e-4ec9-42f5-bb65-611340c68837
31 changes: 14 additions & 17 deletions completions/npm/hooks.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
function handleCompletions([System.Collections.Generic.List[System.Object]]$completions) {
function handleCompletions($completions) {
if (!(Test-Path "package.json")) { return $completions }

$tempList = [System.Collections.Generic.List[System.Object]]@()
function addCompletion($name, $tip = ' ', $symbol = '') {
$tempList = @()
function returnCompletion($name, $tip = ' ', $symbol = '') {
$symbols = foreach ($c in ($symbol -split ' ')) { $PSCompletions.config."symbol_$($c)" }
$symbols = $symbols -join ''
$padSymbols = if ($symbols) { "$($PSCompletions.config.menu_between_item_and_symbol)$($symbols)" }else { '' }
$cmd_arr = $name -split ' '

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

$packageJson = $PSCompletions.ConvertFrom_JsonToHashtable((Get-Content "package.json" -Raw))
Expand All @@ -22,21 +21,19 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
$devDependencies = $packageJson.devDependencies
if ($scripts) {
foreach ($script in $scripts.Keys) {
addCompletion "run $script" "package.json scripts:`n$($scripts.$script)"
$tempList += returnCompletion "run $script" "package.json scripts:`n$($scripts.$script)"
}
}
if ($dependencies) {
foreach ($dependency in $dependencies.Keys) {
addCompletion "uninstall $dependency" "Uninstall dependency: $($dependency) ($($dependencies.$dependency))"

addCompletion "update $dependency" "Current Version: $($dependencies.$dependency)"
$tempList += returnCompletion "uninstall $dependency" "Uninstall dependency: $($dependency) ($($dependencies.$dependency))"
$tempList += returnCompletion "update $dependency" "Current Version: $($dependencies.$dependency)"
}
}
if ($devDependencies) {
foreach ($devDependency in $devDependencies.Keys) {
addCompletion "uninstall $devDependency" "Uninstall devDependency: $($devDependency) ($($devDependencies.$devDependency))"

addCompletion "update $devDependency" "Current Version: $($devDependencies.$devDependency)"
$tempList += returnCompletion "uninstall $devDependency" "Uninstall devDependency: $($devDependency) ($($devDependencies.$devDependency))"
$tempList += returnCompletion "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 @@
cc5dbb96-873d-4a3e-807f-d1e988754ebe
152b6ccf-ea80-4bc0-8b1f-2f0529b3a2dd
42 changes: 21 additions & 21 deletions completions/pnpm/hooks.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function handleCompletions([System.Collections.Generic.List[System.Object]]$completions) {
function handleCompletions($completions) {
if (!(Test-Path "package.json")) { return $completions }

function addCompletion($name, $tip = ' ', $symbol = '') {
$tempList = @()
function returnCompletion($name, $tip = ' ', $symbol = '') {
$symbols = foreach ($c in ($symbol -split ' ')) { $PSCompletions.config."symbol_$($c)" }
$symbols = $symbols -join ''
$padSymbols = if ($symbols) { "$($PSCompletions.config.menu_between_item_and_symbol)$($symbols)" }else { '' }
$cmd_arr = $name -split ' '

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

$packageJson = $PSCompletions.ConvertFrom_JsonToHashtable((Get-Content "package.json" -Raw))
Expand All @@ -21,28 +21,28 @@ function handleCompletions([System.Collections.Generic.List[System.Object]]$comp
$devDependencies = $packageJson.devDependencies
if ($scripts) {
foreach ($script in $scripts.Keys) {
addCompletion "run $script" "package.json scripts:`n$($scripts.$script)"
$tempList += returnCompletion "run $script" "package.json scripts:`n$($scripts.$script)"
}
}
if ($dependencies) {
foreach ($dependency in $dependencies.Keys) {
addCompletion "rm $dependency" "Remove dependency: $($dependency) ($($dependencies.$dependency))"
addCompletion "remove $dependency" "Remove dependency: $($dependency) ($($dependencies.$dependency))"
$tempList += returnCompletion "rm $dependency" "Remove dependency: $($dependency) ($($dependencies.$dependency))"
$tempList += returnCompletion "remove $dependency" "Remove dependency: $($dependency) ($($dependencies.$dependency))"

addCompletion "update $dependency" "Current Version: $($dependencies.$dependency)"
addCompletion "up $dependency" "Current Version: $($dependencies.$dependency)"
addCompletion "upgrade $dependency" "Current Version: $($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)"
}
}
if ($devDependencies) {
foreach ($devDependency in $devDependencies.Keys) {
addCompletion "rm $devDependency" "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))"
addCompletion "remove $devDependency" "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))"
$tempList += returnCompletion "rm $devDependency" "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))"
$tempList += returnCompletion "remove $devDependency" "Remove devDependency: $($devDependency) ($($devDependencies.$devDependency))"

addCompletion "update $devDependency" "Current Version: $($devDependencies.$devDependency)"
addCompletion "up $devDependency" "Current Version: $($devDependencies.$devDependency)"
addCompletion "upgrade $devDependency" "Current Version: $($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)"
}
}
return $completions
return $tempList + $completions
}
2 changes: 1 addition & 1 deletion completions/psc/guid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
00c11c0d-1904-4603-9e57-38717e60e21d
e3fc0933-4ae6-4d9c-8c04-4480dd8d5929
Loading

0 comments on commit 38e2e5d

Please sign in to comment.