summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-04-16 00:48:24 +0800
committerruki <[email protected]>2021-04-16 00:48:24 +0800
commit52d50b181831215fb9dc56448745e8e64895968d (patch)
treecb6ff71ac71e1a0132544f205f2f932086855c85
parent705dca68a2fb2a1fe5b407e2bbaeda2251982b01 (diff)
improve xrepo env
-rw-r--r--xmake/modules/private/xrepo/action/env.lua37
1 files changed, 31 insertions, 6 deletions
diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua
index eaedd1d7c..3866786eb 100644
--- a/xmake/modules/private/xrepo/action/env.lua
+++ b/xmake/modules/private/xrepo/action/env.lua
@@ -232,15 +232,40 @@ function _package_getenvs()
return envs
end
+-- get current shell
+function _get_shell()
+ local shell = os.getenv("SHELL")
+ if shell then
+ for _, shellname in ipairs({"zsh", "bash", "sh"}) do
+ if shell:find(shellname) then
+ return shellname
+ end
+ end
+ end
+ local term = os.term()
+ if term == "cmd" then
+ return "cmd"
+ elseif term == "powershell" then
+ return "powershell"
+ end
+ return "sh"
+end
+
-- run shell
function _run_shell(envs)
- local shell = find_tool("bash") or find_tool("sh")
- if shell then
- local prompt = "xrepo> "
- os.execv(shell.program, option.get("arguments"), {envs = table.join({PS1 = prompt}, envs)})
- elseif is_host("windows") then
- local prompt = "xrepo$G "
+ local shell = _get_shell()
+ local projectname = path.filename(os.projectdir())
+ if shell:endswith("sh") then
+ local prompt = projectname .. "> "
+ os.execv(shell, option.get("arguments"), {envs = table.join({PS1 = prompt}, envs)})
+ elseif shell == "powershell" then
+ -- TODO
+ os.execv("powershell", option.get("arguments"), {envs = envs})
+ elseif shell == "cmd" or is_host("windows") then
+ local prompt = projectname .. "$G "
os.execv("cmd", table.join({"/k", "prompt " .. prompt}, option.get("arguments")), {envs = envs})
+ else
+ assert("shell not found!")
end
end