-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
param([string]$completion_name) | ||
|
||
if (!$PSCompletions) { | ||
Write-Host "You should install PSCompletions module and import it." -ForegroundColor Red | ||
return | ||
} | ||
$path_guide = "$($PSScriptRoot)/template/guide/$($PSCompletions.language).json" | ||
|
||
if (Test-Path $path_guide) { | ||
$guide = Get-Content -Path $path_guide -Encoding utf8 | ConvertFrom-Json | ||
} | ||
else { | ||
$guide = Get-Content -Path "$($PSScriptRoot)/template/guide/en-US.json" -Encoding utf8 | ConvertFrom-Json | ||
} | ||
|
||
if (!$completion_name.Trim()) { | ||
$PSCompletions.write_with_color("<@Red>You should enter an available completion name.`ne.g. <@Magenta>.\scripts\create-completion.ps1 test") | ||
return | ||
} | ||
|
||
$config = @{ | ||
language = @('en-US', 'zh-CN') | ||
} | ||
|
||
$root_dir = Split-Path $PSScriptRoot -Parent | ||
$completion_dir = $PSCompletions.join_path($root_dir, "completions", $completion_name) | ||
if (Test-Path $completion_dir) { | ||
$PSCompletions.write_with_color($guide.exist) | ||
return | ||
} | ||
|
||
# create new completion | ||
$PSCompletions.ensure_dir($completion_dir) | ||
$PSCompletions.ensure_dir("$completion_dir/language") | ||
|
||
[System.Guid]::NewGuid().Guid | Out-File "$completion_dir\guid.txt" -Encoding utf8 -Force | ||
|
||
Copy-Item "$($PSScriptRoot)/template/config.json" "$completion_dir/config.json" -Force | ||
|
||
Copy-Item "$($PSScriptRoot)/template/language/en-US.json" "$completion_dir/language/en-US.json" -Force | ||
Copy-Item "$($PSScriptRoot)/template/language/zh-CN.json" "$completion_dir/language/zh-CN.json" -Force | ||
|
||
|
||
$test_dir = Join-Path $PSCompletions.path.completions $completion_name | ||
Remove-Item $test_dir -Recurse -Force -ErrorAction SilentlyContinue | ||
New-Item -ItemType SymbolicLink -Path $test_dir -Target $completion_dir > $null | ||
$PSCompletions.write_with_color($PSCompletions.replace_content($guide.success)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
param([string]$completion_name) | ||
|
||
if (!$PSCompletions) { | ||
Write-Host "You should install PSCompletions module and import it." -ForegroundColor Red | ||
return | ||
} | ||
if (!$completion_name.Trim()) { | ||
$PSCompletions.write_with_color("<@Red>You should enter an available completion name.`ne.g. <@Magenta>.\scripts\link-completion.ps1 git") | ||
return | ||
} | ||
$root_dir = Split-Path $PSScriptRoot -Parent | ||
$completion_dir = $PSCompletions.join_path($root_dir, "completions", $completion_name) | ||
if (!(Test-Path $completion_dir)) { | ||
$PSCompletions.write_with_color("<@Red><@Magenta>$completion_name<@Red> isn't exist.") | ||
return | ||
} | ||
|
||
$completion_dir = "$($PSCompletions.path.completions)\$completion_name" | ||
Remove-Item $completion_dir -Force -Recurse -ErrorAction SilentlyContinue | ||
New-Item -ItemType SymbolicLink -Path $completion_dir -Target "$PSScriptRoot\..\completions\$completion_name" -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters