summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-26 00:04:01 +0800
committerruki <[email protected]>2026-03-26 00:04:01 +0800
commit887a080771e66e6488dfb68f16074dbeea461b25 (patch)
tree30b625504279bb00252cd5a11e2a12d7f371e36d
parente3f123981d80c54af1b29b87a4a173557a51d73d (diff)
improve completions
-rw-r--r--xmake/modules/private/utils/completer.lua3
-rw-r--r--xmake/scripts/completions/register-completions.bash4
-rw-r--r--xmake/scripts/completions/register-completions.fish2
-rw-r--r--xmake/scripts/completions/register-completions.zsh4
-rw-r--r--xmake/scripts/profile-win.ps110
5 files changed, 16 insertions, 7 deletions
diff --git a/xmake/modules/private/utils/completer.lua b/xmake/modules/private/utils/completer.lua
index c98f3b672..38751abd7 100644
--- a/xmake/modules/private/utils/completer.lua
+++ b/xmake/modules/private/utils/completer.lua
@@ -203,6 +203,9 @@ function completer:_complete_option_v(options, current, completing)
end
-- transform values array to candidates array
local function _transform_values(values)
+ if not values then
+ return {}
+ end
local candidates = {}
if #values > 0 and type(values[1]) == "string" then
for _, v in ipairs(values) do
diff --git a/xmake/scripts/completions/register-completions.bash b/xmake/scripts/completions/register-completions.bash
index 4d02131f3..15c432f42 100644
--- a/xmake/scripts/completions/register-completions.bash
+++ b/xmake/scripts/completions/register-completions.bash
@@ -23,7 +23,7 @@ _xmake_bash_complete()
{
local word=${COMP_WORDS[COMP_CWORD]}
local completions
- completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")"
+ completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y XMAKE_COLORTERM=nocolor xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}" 2>/dev/null)"
if [ $? -ne 0 ]; then
completions=""
fi
@@ -36,7 +36,7 @@ _xrepo_bash_complete()
{
local word=${COMP_WORDS[COMP_CWORD]}
local completions
- completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")"
+ completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y XMAKE_COLORTERM=nocolor xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}" 2>/dev/null)"
if [ $? -ne 0 ]; then
completions=""
fi
diff --git a/xmake/scripts/completions/register-completions.fish b/xmake/scripts/completions/register-completions.fish
index 05258bfd7..a48cfc1a4 100644
--- a/xmake/scripts/completions/register-completions.fish
+++ b/xmake/scripts/completions/register-completions.fish
@@ -27,7 +27,7 @@ function _xmake_fish_complete
set -l token (commandline -ot)
# Call XMake built-in completion to get available results
- set -l result (MAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$raw_cmd")
+ set -l result (XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y XMAKE_COLORTERM=nocolor xmake lua private.utils.complete 0 nospace "$raw_cmd" 2>/dev/null)
if test (count $result) -lt 1
# When there are no available completions, the function ends immediately
# Otherwise, the subsequent `contains` command will trigger an error
diff --git a/xmake/scripts/completions/register-completions.zsh b/xmake/scripts/completions/register-completions.zsh
index e4010efe7..8817104ae 100644
--- a/xmake/scripts/completions/register-completions.zsh
+++ b/xmake/scripts/completions/register-completions.zsh
@@ -22,13 +22,13 @@
# zsh parameter completion for xmake
_xmake_zsh_complete() {
- local completions=("${(@f)$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")}")
+ local completions=("${(@f)$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y XMAKE_COLORTERM=nocolor xmake lua private.utils.complete 0 nospace "$words" 2>/dev/null)}")
compadd -Q -S '' -- ${completions[@]}
}
# zsh parameter completion for xrepo
_xrepo_zsh_complete() {
- local completions=("${(@f)$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")}")
+ local completions=("${(@f)$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y XMAKE_COLORTERM=nocolor xmake lua private.xrepo.complete 0 nospace "$words" 2>/dev/null)}")
compadd -Q -S '' -- ${completions[@]}
}
diff --git a/xmake/scripts/profile-win.ps1 b/xmake/scripts/profile-win.ps1
index 201f291cd..a708a8893 100644
--- a/xmake/scripts/profile-win.ps1
+++ b/xmake/scripts/profile-win.ps1
@@ -6,8 +6,10 @@ Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock {
$complete = $complete + " "
}
$oldenv = $env:XMAKE_SKIP_HISTORY
+ $oldcolor = $env:XMAKE_COLORTERM
$env:XMAKE_SKIP_HISTORY = 1
- $results = xmake lua "private.utils.complete" $cursorPosition "nospace-json" "$complete" | ConvertFrom-Json | Sort-Object -Property value
+ $env:XMAKE_COLORTERM = "nocolor"
+ $results = xmake lua "private.utils.complete" $cursorPosition "nospace-json" "$complete" 2>$null | ConvertFrom-Json | Sort-Object -Property value
$results | ForEach-Object {
$hasdesc = [bool] $_.psobject.Properties['description']
if ($hasdesc) {
@@ -18,6 +20,7 @@ Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock {
[System.Management.Automation.CompletionResult]::new($_.value, "$($_.value)$desc", 'ParameterValue', $_.value)
}
$env:XMAKE_SKIP_HISTORY = $oldenv
+ $env:XMAKE_COLORTERM = $oldcolor
}
# PowerShell parameter completion for xrepo
@@ -28,8 +31,10 @@ Register-ArgumentCompleter -Native -CommandName xrepo -ScriptBlock {
$complete = $complete + " "
}
$oldenv = $env:XMAKE_SKIP_HISTORY
+ $oldcolor = $env:XMAKE_COLORTERM
$env:XMAKE_SKIP_HISTORY = 1
- $results = xmake lua "private.xrepo.complete" $cursorPosition "nospace-json" "$complete" | ConvertFrom-Json | Sort-Object -Property value
+ $env:XMAKE_COLORTERM = "nocolor"
+ $results = xmake lua "private.xrepo.complete" $cursorPosition "nospace-json" "$complete" 2>$null | ConvertFrom-Json | Sort-Object -Property value
$results | ForEach-Object {
$hasdesc = [bool] $_.psobject.Properties['description']
if ($hasdesc) {
@@ -40,4 +45,5 @@ Register-ArgumentCompleter -Native -CommandName xrepo -ScriptBlock {
[System.Management.Automation.CompletionResult]::new($_.value, "$($_.value)$desc", 'ParameterValue', $_.value)
}
$env:XMAKE_SKIP_HISTORY = $oldenv
+ $env:XMAKE_COLORTERM = $oldcolor
} \ No newline at end of file