diff options
| author | Saikari <[email protected]> | 2026-01-31 19:29:14 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-01-31 19:29:14 +0300 |
| commit | b56818e7a2f96f1750545deda8a0e7bae53baf68 (patch) | |
| tree | f836decc7abfd726c1168e28eccad62cd7ed0e1a /xmake/core/base/tty.lua | |
| parent | e494d44263b18e2981cb35041817b052a2bdda6a (diff) | |
add process retrieval for Windows in tty and winos modules
Diffstat (limited to 'xmake/core/base/tty.lua')
| -rw-r--r-- | xmake/core/base/tty.lua | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua index b3ac35b2b..8d506336d 100644 --- a/xmake/core/base/tty.lua +++ b/xmake/core/base/tty.lua @@ -237,11 +237,53 @@ end -- find the shell from the parent process (linux) function tty._find_shell_from_parent() + local shell + if os.host() == "windows" then + local winos = require("base/winos") + if winos.processes then + local processes = winos.processes() + if processes then + local pid = os.getpid() + local processes_map = {} + for _, process in ipairs(processes) do + processes_map[process.pid] = process + end + local count = 0 + while pid and pid ~= 0 and count < 10 do + count = count + 1 + local process = processes_map[pid] + if not process then + break + end + local name = process.name + if name then + name = name:lower() + if name:sub(-4) == ".exe" then + name = name:sub(1, #name - 4) + end + for _, shellname in ipairs({"zsh", "bash", "fish", "nu", "elvish", "pwsh", "powershell", "cmd", "sh"}) do + if name == shellname then + shell = shellname + break + end + end + end + if shell then + break + end + pid = process.ppid + end + end + end + end + if shell then + return shell + end + if os.host() ~= "linux" or not os.isfile("/proc/self/stat") then return end - local shell local pid = os.getpid() local count = 0 while pid ~= 0 and count < 4 do @@ -295,22 +337,7 @@ function tty.shell() if os.getenv("NU_VERSION") then shell = "nu" end - if not shell then - local subhost = xmake._SUBHOST - if subhost == "windows" then - if os.getenv("PROMPT") then - shell = "cmd" - else - local ok, result = os.iorun("pwsh -v") - if ok then - shell = "pwsh" - else - shell = "powershell" - end - end - end - end - -- try to find the shell from the parent process (linux) + -- try to find the shell from the parent process if not shell then shell = tty._find_shell_from_parent() end |
