summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-26 06:36:04 +0800
committerGitHub <[email protected]>2026-03-26 06:36:04 +0800
commit76ecc812e959a271e2ebc476073948e354e643ea (patch)
tree30b625504279bb00252cd5a11e2a12d7f371e36d
parent27168978bb7dd590192be1eee73beea969272b27 (diff)
parent887a080771e66e6488dfb68f16074dbeea461b25 (diff)
Merge pull request #7420 from xmake-io/zsh
improve zsh 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.zsh26
-rw-r--r--xmake/scripts/profile-win.ps110
5 files changed, 26 insertions, 19 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 2ddbe08e2..8817104ae 100644
--- a/xmake/scripts/completions/register-completions.zsh
+++ b/xmake/scripts/completions/register-completions.zsh
@@ -1,3 +1,5 @@
+#compdef xmake xrepo
+#
# A cross-platform build utility based on Lua
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,22 +21,18 @@
#
# zsh parameter completion for xmake
-_xmake_zsh_complete()
-{
- local words
- read -Ac words
- local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")")
- reply=( "${(ps:\n:)completions}" )
+_xmake_zsh_complete() {
+ 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[@]}
}
-compctl -f -S "" -K _xmake_zsh_complete xmake
# zsh parameter completion for xrepo
-_xrepo_zsh_complete()
-{
- local words
- read -Ac words
- local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")")
- reply=( "${(ps:\n:)completions}" )
+_xrepo_zsh_complete() {
+ 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[@]}
}
-compctl -f -S "" -K _xrepo_zsh_complete xrepo
+case "$service" in
+ xmake) _xmake_zsh_complete ;;
+ xrepo) _xrepo_zsh_complete ;;
+esac
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