summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-30 19:09:10 +0800
committerGitHub <[email protected]>2019-08-30 19:09:10 +0800
commitf14db9813059078fa141fc285245009667f775f6 (patch)
tree0e9241715a63885d40833e419c9da0e4789b5171
parent00709d887ac44a69eecda7259bb4e119d74470aa (diff)
parent416efddbbac77ecad9be41bdafd36bdea89e25d5 (diff)
Merge pull request #557 from OpportunityLiu/dev
add XMAKE_SKIP_HISTORY
-rw-r--r--scripts/get.ps126
-rwxr-xr-xscripts/get.sh4
-rw-r--r--scripts/register-completions.bash2
-rw-r--r--scripts/register-completions.ps14
-rw-r--r--scripts/register-completions.zsh2
-rw-r--r--xmake/core/main.lua5
-rw-r--r--xmake/plugins/project/vsxmake/vsproj/Xmake.targets1
7 files changed, 21 insertions, 23 deletions
diff --git a/scripts/get.ps1 b/scripts/get.ps1
index 28be8f382..4ec3df140 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 -NoNewline
} 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*", "`n", [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/get.sh b/scripts/get.sh
index 5ae3f8513..7616a3dd1 100755
--- a/scripts/get.sh
+++ b/scripts/get.sh
@@ -169,7 +169,7 @@ if [[ "$SHELL" = */zsh ]]; then
_xmake_zsh_complete()
{
- local completions=("$(xmake lua private.utils.complete 0 nospace "$words")")
+ local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete 0 nospace "$words")")
reply=( "${(ps:\n:)completions}" )
}
@@ -184,7 +184,7 @@ elif [[ "$SHELL" = */bash ]]; then
local word=${COMP_WORDS[COMP_CWORD]}
local completions
- completions="$(xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
+ completions="$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
if [ $? -ne 0 ]; then
completions=""
fi
diff --git a/scripts/register-completions.bash b/scripts/register-completions.bash
index 64655760d..9d5865cd6 100644
--- a/scripts/register-completions.bash
+++ b/scripts/register-completions.bash
@@ -5,7 +5,7 @@ _xmake_bash_complete()
local word=${COMP_WORDS[COMP_CWORD]}
local completions
- completions="$(xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
+ completions="$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
if [ $? -ne 0 ]; then
completions=""
fi
diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1
index 6295cf4fc..bae3281f8 100644
--- a/scripts/register-completions.ps1
+++ b/scripts/register-completions.ps1
@@ -6,8 +6,10 @@ Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock {
if (-not $commandName) {
$complete = $complete + " "
}
+ $oldenv = $env:XMAKE_SKIP_HISTORY
+ $env:XMAKE_SKIP_HISTORY = 1
xmake lua private.utils.complete "0" "$complete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
+ $env:XMAKE_SKIP_HISTORY = $oldenv
}
-
diff --git a/scripts/register-completions.zsh b/scripts/register-completions.zsh
index 509816e56..82f588d5f 100644
--- a/scripts/register-completions.zsh
+++ b/scripts/register-completions.zsh
@@ -2,7 +2,7 @@
_xmake_zsh_complete()
{
- local completions=("$(xmake lua private.utils.complete 0 nospace "$words")")
+ local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete 0 nospace "$words")")
reply=( "${(ps:\n:)completions}" )
}
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index 4ac0792bb..3d305a345 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -220,13 +220,14 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily.
end
-- save command lines to history
- if os.isfile(os.projectfile()) then
+ local skipHistory = (os.getenv('XMAKE_SKIP_HISTORY') or ''):trim()
+ if os.isfile(os.projectfile()) and skipHistory == '' then
history("local.history"):save("cmdlines", option.cmdline())
end
-- get task instance
local taskname = option.taskname() or "build"
- local taskinst = project.task(taskname) or task.task(taskname)
+ local taskinst = project.task(taskname) or task.task(taskname)
if not taskinst then
utils.error("do unknown task(%s)!", taskname)
return -1
diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets
index 2c3a89293..40ef5fc05 100644
--- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets
+++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets
@@ -69,6 +69,7 @@
pushd $(XmakeProjectDirResolved)
set XMAKE_CONFIGDIR=$(XmakeConfigDirResolved.TrimEnd('/\'.ToCharArray()))
set XMAKE_PROGRAM_DIR=$(XmakeProgramDirResolved.TrimEnd('/\'.ToCharArray()))
+ set XMAKE_SKIP_HISTORY=1
</_XmakeEnv>
<_XmakeEnv Condition="$(XmakeDiagnosis)">
$(_XmakeEnv)