summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-06-06 12:45:06 +0800
committerGitHub <[email protected]>2019-06-06 12:45:06 +0800
commit12671e1c0af4e86d1ee73ccd13ff35defde7dc4b (patch)
tree5e833758b969884f19c3a9cc10a69efba8f9fe62
parent4c7dc142394d23b213071ff057c383204f716eaa (diff)
parent69c93dba3591d9404bc6b38d84aca731db84ad15 (diff)
Merge pull request #445 from OpportunityLiu/tap-completion
Improve tab completion
-rwxr-xr-xscripts/get.sh26
-rw-r--r--scripts/register-completions.bash2
-rw-r--r--scripts/register-completions.zsh4
-rw-r--r--xmake/modules/private/utils/complete.lua34
-rw-r--r--xmake/plugins/lua/xmake.lua4
5 files changed, 41 insertions, 29 deletions
diff --git a/scripts/get.sh b/scripts/get.sh
index 164ec9c48..e89afea97 100755
--- a/scripts/get.sh
+++ b/scripts/get.sh
@@ -149,36 +149,34 @@ install_profile()
echo "export PATH=$prefix/bin:\$PATH" > ~/.xmake/profile
echo '
if [[ "$SHELL" = */zsh ]]; then
-
# zsh parameter completion for xmake
_xmake_zsh_complete()
{
- local completions=("$(xmake lua private.utils.complete 0 "$words")")
+ local completions=("$(xmake lua private.utils.complete 0 nospace "$words")")
- reply=( "${(ps:\n:)completions}" )
+ reply=( "${(ps:\n:)completions}" )
}
- compctl -K _xmake_zsh_complete xmake
+ compctl -f -S "" -K _xmake_zsh_complete xmake
elif [[ "$SHELL" = */bash ]]; then
-
-# bash parameter completion for xmake
+ # bash parameter completion for xmake
_xmake_bash_complete()
{
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word=${COMP_WORDS[COMP_CWORD]}
- local completions
- completions="$(xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
- if [ $? -ne 0 ]; then
- completions=""
- fi
+ local completions
+ completions="$(xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
+ if [ $? -ne 0 ]; then
+ completions=""
+ fi
- COMPREPLY=( $(compgen -W "$completions" -- "$word") )
+ COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}
- complete -f -F _xmake_bash_complete xmake
+ complete -o default -o nospace -F _xmake_bash_complete xmake
fi
' >> ~/.xmake/profile
diff --git a/scripts/register-completions.bash b/scripts/register-completions.bash
index 11cadedf3..64655760d 100644
--- a/scripts/register-completions.bash
+++ b/scripts/register-completions.bash
@@ -13,4 +13,4 @@ _xmake_bash_complete()
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}
-complete -f -F _xmake_bash_complete xmake
+complete -o default -o nospace -F _xmake_bash_complete xmake
diff --git a/scripts/register-completions.zsh b/scripts/register-completions.zsh
index ff019569f..509816e56 100644
--- a/scripts/register-completions.zsh
+++ b/scripts/register-completions.zsh
@@ -2,9 +2,9 @@
_xmake_zsh_complete()
{
- local completions=("$(xmake lua private.utils.complete 0 "$words")")
+ local completions=("$(xmake lua private.utils.complete 0 nospace "$words")")
reply=( "${(ps:\n:)completions}" )
}
-compctl -K _xmake_zsh_complete xmake
+compctl -f -S "" -K _xmake_zsh_complete xmake
diff --git a/xmake/modules/private/utils/complete.lua b/xmake/modules/private/utils/complete.lua
index 1e51f8d8f..af393cb7f 100644
--- a/xmake/modules/private/utils/complete.lua
+++ b/xmake/modules/private/utils/complete.lua
@@ -22,10 +22,17 @@
import("core.base.option")
import("core.base.task")
-function _print_candidate(...)
+local use_spaces = true
+
+function _print_candidate(is_complate, ...)
local candidate = format(...)
if candidate and #candidate ~= 0 then
- print(candidate)
+ printf(candidate)
+ if use_spaces and is_complate then
+ print(" ")
+ else
+ print("")
+ end
end
end
@@ -33,14 +40,14 @@ function _complete_task(tasks, name)
local has_candidate = false
for k, _ in pairs(tasks) do
if k:startswith(name) then
- _print_candidate(k)
+ _print_candidate(true, "%s", k)
has_candidate = true
end
end
for k, _ in pairs(tasks) do
-- not startswith
if k:find(name, 2, true) then
- _print_candidate(k)
+ _print_candidate(true, "%s", k)
has_candidate = true
end
end
@@ -69,9 +76,9 @@ function _complete_option(options, name)
for _, v in ipairs(opcandi) do
if (state == 2 or state == 0) and v[2]:startswith(name) then
- _print_candidate((v[3] == "k") and "--%s" or "--%s=", v[2])
+ _print_candidate((v[3] == "k"), (v[3] == "k") and "--%s" or "--%s=", v[2])
elseif (state == 1 or state == 0) and v[1] and v[1]:startswith(name) then
- _print_candidate((v[3] == "k") and "-%s" or "-%s ", v[1])
+ _print_candidate(true, "-%s", v[1])
end
end
@@ -82,15 +89,22 @@ function _complete_option(options, name)
for _, v in ipairs(opcandi) do
-- not startswith
if (state == 2 or state == 0) and v[2]:find(name, 2, true) then
- _print_candidate((v[3] == "k") and "--%s" or "--%s=", v[2])
+ _print_candidate((v[3] == "k"), (v[3] == "k") and "--%s" or "--%s=", v[2])
elseif (state == 1 or state == 0) and v[1] and v[1]:find(name, 2, true) then
- _print_candidate((v[3] == "k") and "-%s" or "-%s ", v[1])
+ _print_candidate(true, "-%s", v[1])
end
end
end
-function main(position, ...)
- local word = table.concat({...}, " ") or ""
+function main(position, config_use_spaces, ...)
+ local words = {...}
+ if config_use_spaces == "nospace" then
+ use_spaces = false
+ else
+ table.insert(words, 1, config_use_spaces)
+ end
+
+ local word = table.concat(words, " ") or ""
position = tonumber(position) or 0
local has_space = word:endswith(" ") or position > #word
word = word:trim()
diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua
index 11fce7a20..26067e90e 100644
--- a/xmake/plugins/lua/xmake.lua
+++ b/xmake/plugins/lua/xmake.lua
@@ -39,7 +39,7 @@ task("lua")
for _, file in ipairs(files) do
print(" " .. path.basename(file))
end
- return
+ return
end
-- run command?
@@ -50,7 +50,7 @@ task("lua")
script = tmpfile
end
- -- get script
+ -- get script
if script then
-- import and run script