diff options
| author | ruki <[email protected]> | 2021-04-16 15:10:57 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-04-16 15:10:57 +0800 |
| commit | a87d6552004a1fb9f89c29bb89f6918b22aedb3c (patch) | |
| tree | 64f04062897e929a8cd0eda6d5f419a071c2d676 /xmake/modules | |
| parent | e7a60dae13e583aa8616dcdc37742ff1b7b17ddd (diff) | |
| parent | 1c745e5cfe8e28f8ab4b19bfecce22faccc9aa90 (diff) | |
Merge pull request #1340 from xq114/dev
improve xrepo env
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/xrepo/action/env.lua | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 3866786eb..893b68cce 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -232,38 +232,23 @@ 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 = _get_shell() + local shell = os.shell() local projectname = path.filename(os.projectdir()) - if shell:endswith("sh") then - local prompt = projectname .. "> " + if shell == "pwsh" then + local args = table.join({"-c", "'function prompt { \\\"[" .. projectname .. "] \\\" + $(Get-Location) + \\\"> \\\" }'"}, option.get("arguments")) + os.execv("pwsh", args, {envs = envs}) + elseif shell:endswith("sh") then + local prompt = "[" .. projectname .. "] " .. (os.getenv("PS1") or "\\W $ ") 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}) + 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 |
