From 78e0d4e9e9752f440b645f86db9d3c8eb14e44ca Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 25 Mar 2026 22:35:07 +0800 Subject: improve zsh completions --- xmake/scripts/completions/register-completions.zsh | 45 ++++++++++++++-------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/xmake/scripts/completions/register-completions.zsh b/xmake/scripts/completions/register-completions.zsh index 2ddbe08e2..1c4c09fa1 100644 --- a/xmake/scripts/completions/register-completions.zsh +++ b/xmake/scripts/completions/register-completions.zsh @@ -18,23 +18,36 @@ # @homepage register-completions.zsh # -# 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}" ) +# zsh parameter completion for xmake (using compsys) +_xmake_zsh_complete() { + local completions=("${(@f)$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")}") + 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}" ) +# zsh parameter completion for xrepo (using compsys) +_xrepo_zsh_complete() { + local completions=("${(@f)$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")}") + compadd -Q -S '' -- ${completions[@]} } -compctl -f -S "" -K _xrepo_zsh_complete xrepo +# register completions using compdef (modern zsh completion system) +if (( $+functions[compdef] )); then + compdef _xmake_zsh_complete xmake + compdef _xrepo_zsh_complete xrepo +else + # fallback to compctl for older zsh without compsys + _xmake_zsh_complete_legacy() { + 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}" ) + } + _xrepo_zsh_complete_legacy() { + 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}" ) + } + compctl -f -S "" -K _xmake_zsh_complete_legacy xmake + compctl -f -S "" -K _xrepo_zsh_complete_legacy xrepo +fi -- cgit v1.3.1 From e3f123981d80c54af1b29b87a4a173557a51d73d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 25 Mar 2026 23:19:43 +0800 Subject: fix complete again --- xmake/scripts/completions/register-completions.zsh | 31 ++++++---------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/xmake/scripts/completions/register-completions.zsh b/xmake/scripts/completions/register-completions.zsh index 1c4c09fa1..e4010efe7 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"); @@ -18,36 +20,19 @@ # @homepage register-completions.zsh # -# zsh parameter completion for xmake (using compsys) +# 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")}") compadd -Q -S '' -- ${completions[@]} } -# zsh parameter completion for xrepo (using compsys) +# 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")}") compadd -Q -S '' -- ${completions[@]} } -# register completions using compdef (modern zsh completion system) -if (( $+functions[compdef] )); then - compdef _xmake_zsh_complete xmake - compdef _xrepo_zsh_complete xrepo -else - # fallback to compctl for older zsh without compsys - _xmake_zsh_complete_legacy() { - 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}" ) - } - _xrepo_zsh_complete_legacy() { - 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}" ) - } - compctl -f -S "" -K _xmake_zsh_complete_legacy xmake - compctl -f -S "" -K _xrepo_zsh_complete_legacy xrepo -fi +case "$service" in + xmake) _xmake_zsh_complete ;; + xrepo) _xrepo_zsh_complete ;; +esac -- cgit v1.3.1 From 887a080771e66e6488dfb68f16074dbeea461b25 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 26 Mar 2026 00:04:01 +0800 Subject: improve completions --- xmake/modules/private/utils/completer.lua | 3 +++ xmake/scripts/completions/register-completions.bash | 4 ++-- xmake/scripts/completions/register-completions.fish | 2 +- xmake/scripts/completions/register-completions.zsh | 4 ++-- xmake/scripts/profile-win.ps1 | 10 ++++++++-- 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 -- cgit v1.3.1