summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-01-31 19:29:14 +0300
committerSaikari <[email protected]>2026-01-31 19:29:14 +0300
commitb56818e7a2f96f1750545deda8a0e7bae53baf68 (patch)
treef836decc7abfd726c1168e28eccad62cd7ed0e1a
parente494d44263b18e2981cb35041817b052a2bdda6a (diff)
add process retrieval for Windows in tty and winos modules
-rw-r--r--xmake/core/base/tty.lua61
-rw-r--r--xmake/core/base/winos.lua5
-rw-r--r--xmake/core/sandbox/modules/winos.lua1
3 files changed, 50 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
diff --git a/xmake/core/base/winos.lua b/xmake/core/base/winos.lua
index 73657662e..9d786fdfc 100644
--- a/xmake/core/base/winos.lua
+++ b/xmake/core/base/winos.lua
@@ -31,6 +31,7 @@ winos._oem_cp = winos._oem_cp or winos.oem_cp
winos._registry_query = winos._registry_query or winos.registry_query
winos._registry_keys = winos._registry_keys or winos.registry_keys
winos._registry_values = winos._registry_values or winos.registry_values
+winos._processes = winos._processes or winos.processes
function winos.ansi_cp()
if not winos._ANSI_CP then
@@ -46,6 +47,10 @@ function winos.oem_cp()
return winos._OEM_CP
end
+if not winos.processes then
+ winos.processes = winos._processes
+end
+
-- get windows version from name
function winos._version_from_name(name)
winos._VERSIONS = winos._VERSIONS or {
diff --git a/xmake/core/sandbox/modules/winos.lua b/xmake/core/sandbox/modules/winos.lua
index fec1d07df..eddcf91d4 100644
--- a/xmake/core/sandbox/modules/winos.lua
+++ b/xmake/core/sandbox/modules/winos.lua
@@ -33,6 +33,7 @@ sandbox_winos.console_cp = winos.console_cp
sandbox_winos.console_output_cp = winos.console_output_cp
sandbox_winos.logical_drives = winos.logical_drives
sandbox_winos.cmdargv = winos.cmdargv
+sandbox_winos.processes = winos.processes
sandbox_winos.inherit_handles_safely = winos.inherit_handles_safely
-- get windows system version