summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-08-30 16:52:58 +0800
committerOpportunityLiu <[email protected]>2019-08-30 16:52:58 +0800
commit27151c9ec191e0e9cfba633bec242fe70eb78a0b (patch)
treea0e6e9efcfacd94b8a0b1605fa2d63a7af121346 /scripts
parent499f64300634421754fde8c5f139f8055dd1fa25 (diff)
fix install script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/get.ps126
-rw-r--r--scripts/register-completions.ps11
2 files changed, 10 insertions, 17 deletions
diff --git a/scripts/get.ps1 b/scripts/get.ps1
index 28be8f382..878ab1283 100644
--- a/scripts/get.ps1
+++ b/scripts/get.ps1
@@ -11,6 +11,7 @@ param (
)
& {
+ $ErrorActionPreference = 'Stop'
function writeErrorTip($msg) {
Write-Host $msg -BackgroundColor Red -ForegroundColor White
@@ -134,38 +135,31 @@ param (
function registerTabCompletion {
function writeDataToFile($file) {
- $encoding = [text.encoding]::UTF8
+ $content = ''
if (Test-Path $file -PathType Leaf) {
- #Create a stream reader to get the file's encoding and contents.
- $sr = New-Object System.IO.StreamReader($file, $true)
- [char[]] $buffer = new-object char[] 3
- $sr.Read($buffer, 0, 3) | Out-Null
- $encoding = $sr.CurrentEncoding
- $sr.Close() | Out-Null
-
- if ($(Get-Content $file) -imatch "Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock") {
- Write-Host "Seems the tab completion of xmake has installed here... skipped"
- return
- }
+ $content = Get-Content $file -Raw
}
try {
New-Item $(Split-Path $file -Parent) -ItemType Directory -Force | Out-Null
- [IO.File]::AppendAllText($file, "`n", $encoding)
+ Set-Content $file $content
} catch {
writeErrorTip "Failed to append to profile!"
writeErrorTip "Please try again as administrator"
return
}
+
+ if ($content) {
+ $content = [System.Text.RegularExpressions.Regex]::Replace($content, "\n?(# PowerShell parameter completion shim for xmake)?\s*Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock\s*{.+?\n}\s*", "", [System.Text.RegularExpressions.RegexOptions]::Singleline)
+ }
try {
- $content = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content
+ $appendcontent = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content
} catch {
writeErrorTip 'Download failed!'
writeErrorTip 'Check your network or... the news of S3 break'
return
}
- [IO.File]::AppendAllText($file, $content, $encoding)
- [IO.File]::AppendAllText($file, "`n", $encoding)
+ Set-Content $file "$content`n$appendcontent" -NoNewline
. $file
Write-Host "Tab completion installed"
}
diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1
index b58b07cf9..bae3281f8 100644
--- a/scripts/register-completions.ps1
+++ b/scripts/register-completions.ps1
@@ -13,4 +13,3 @@ Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock {
}
$env:XMAKE_SKIP_HISTORY = $oldenv
}
-