diff options
| author | ruki <[email protected]> | 2026-01-28 22:00:56 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-28 22:00:56 +0800 |
| commit | 5c99e2d9e452e08de4fd7595f4429790ce8efed7 (patch) | |
| tree | 56666446a6d95cfe73e6010fdafc494f3b2f3158 | |
| parent | 9914c5cb87077a289f2ec32e360762e91a4378e4 (diff) | |
Update tty.lua
| -rw-r--r-- | xmake/core/base/tty.lua | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua index 0144795f9..b3ac35b2b 100644 --- a/xmake/core/base/tty.lua +++ b/xmake/core/base/tty.lua @@ -243,7 +243,6 @@ function tty._find_shell_from_parent() local shell local pid = os.getpid() - local tmpfile = os.tmpfile() local count = 0 while pid ~= 0 and count < 4 do count = count + 1 @@ -258,12 +257,8 @@ function tty._find_shell_from_parent() if not shell_path and os.isfile("/proc/" .. pid .. "/comm") then shell_name = io.readfile("/proc/" .. pid .. "/comm") - if not shell_name or #shell_name == 0 then - os.runv("cp", {"/proc/" .. pid .. "/comm", tmpfile}) - shell_name = io.readfile(tmpfile) - end if shell_name then - shell_name = shell_name:match("^%s*(.-)%s*$") + shell_name = shell_name:trim() end end if shell_path then @@ -271,27 +266,25 @@ function tty._find_shell_from_parent() end if shell_name then - shell_name = shell_name:gsub("^-", "") + shell_name = shell_name:ltrim("-") for _, name in ipairs({"zsh", "bash", "fish", "nu", "elvish", "pwsh", "sh"}) do if shell_name == name then shell = name break end end - if shell then break end + if shell then + break + end end local stat = io.readfile("/proc/" .. pid .. "/stat") - if not stat or #stat == 0 then - os.runv("cp", {"/proc/" .. pid .. "/stat", tmpfile}) - stat = io.readfile(tmpfile) - end - local ppid = stat and tonumber(stat:match(".*%) %S+ (%d+)")) - if not ppid or ppid == 0 then break end + if not ppid or ppid == 0 then + break + end pid = ppid end - os.rm(tmpfile) return shell end @@ -628,4 +621,3 @@ end -- return module return tty - |
