Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lua/opencode/cli/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ local function get_processes_unix()
assert(vim.fn.executable("pgrep") == 1, "`pgrep` executable not found")
assert(vim.fn.executable("lsof") == 1, "`lsof` executable not found")

-- Find PIDs by command line pattern (handles process names like 'bun', 'node', etc.)
local pgrep_output = exec("pgrep -f 'opencode' 2>/dev/null || true")
-- Find PIDs by command line pattern (handles process names like 'bun', 'node', etc. starting `opencode`).
-- We filter for `--port` to avoid matching other opencode-related processes,
-- and find only servers.
-- While the later CWD check will filter those out too, this is much faster.
local pgrep_output = exec("pgrep -lfa 'opencode' | grep '[-]-port' 2>/dev/null || true")
if pgrep_output == "" then
return {}
end

local processes = {}
for pid_str in pgrep_output:gmatch("[^\r\n]+") do
local pid = tonumber(pid_str)
local pid = tonumber(vim.split(pid_str, "%s+")[1])
if pid then
local lsof_output = exec("lsof -w -iTCP -sTCP:LISTEN -P -n -a -p " .. pid .. " 2>/dev/null || true")

Expand Down