diff options
| author | xq114 <[email protected]> | 2021-04-16 11:05:10 +0800 |
|---|---|---|
| committer | xq114 <[email protected]> | 2021-04-16 11:05:10 +0800 |
| commit | b335fe5f2a21b0663fe0347069940ed5e7f5f5f8 (patch) | |
| tree | 49e9a7a4bcbf4e1add146d5ea7e28df4f3d8e62a | |
| parent | e7a60dae13e583aa8616dcdc37742ff1b7b17ddd (diff) | |
improve xrepo env
| -rw-r--r-- | xmake/modules/private/xrepo/action/env.lua | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 3866786eb..04e68726a 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -23,6 +23,7 @@ import("core.base.option") import("core.base.task") import("core.project.config") import("lib.detect.find_tool") +import("lib.detect.find_program") import("private.action.require.impl.package") import("private.action.require.impl.utils.get_requires") @@ -242,10 +243,11 @@ function _get_shell() end end end - local term = os.term() - if term == "cmd" then + if os.getenv("PROMPT") then return "cmd" - elseif term == "powershell" then + elseif find_program("pwsh") then + return "pwsh" + else return "powershell" end return "sh" @@ -256,14 +258,18 @@ function _run_shell(envs) local shell = _get_shell() local projectname = path.filename(os.projectdir()) if shell:endswith("sh") then - local prompt = projectname .. "> " + local prompt = "[" .. projectname .. "] " .. os.getenv("PS1") os.execv(shell, option.get("arguments"), {envs = table.join({PS1 = prompt}, envs)}) + elseif shell == "pwsh" then + local args = table.join({"-c", "'function prompt { \\\"[" .. projectname .. "] \\\" + $(Get-Location) + \\\"> \\\" }'"}, option.get("arguments")) + os.execv("pwsh", args, {envs = envs}) elseif shell == "powershell" then - -- TODO - os.execv("powershell", option.get("arguments"), {envs = envs}) + local args = table.join({"-c", "'function prompt { \\\"[" .. projectname .. "] \\\" + $(Get-Location) + \\\"> \\\" }'"}, option.get("arguments")) + os.execv("powershell", args, {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}) + local prompt = "[" .. projectname .. "] $P$G" + local args = table.join({"/k", "set PROMPT=[" .. projectname .. "] $P$G"}, option.get("arguments")) + os.execv("cmd", args, {envs = envs}) else assert("shell not found!") end |
