From e008511d70443959cc1814f8fe8fcf08f4c714a3 Mon Sep 17 00:00:00 2001 From: Danick Fort Date: Mon, 30 Nov 2026 08:38:02 +0100 Subject: [PATCH 1/5] feat: show Docker container names in Development servers Docker and OrbStack publish container ports through a helper process, so every container port was listed as that helper. Map published host ports to container names with docker ps when docker is available. --- packages/dev-servers/README.md | 2 ++ packages/dev-servers/package.json | 2 +- packages/dev-servers/scripts/servers.sh | 11 +++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/dev-servers/README.md b/packages/dev-servers/README.md index 1452557..a8943a5 100644 --- a/packages/dev-servers/README.md +++ b/packages/dev-servers/README.md @@ -3,6 +3,8 @@ Shows the number of distinct listening TCP ports owned by your user. **Port range** defaults to `3000-9999`. The popup lists each port and process and updates every five seconds. IPv4 and IPv6 sockets from the same process on the same port appear once. +Ports that Docker or OrbStack publish show the container's name instead of the helper process, +when `docker` is on your PATH. Click an address to open `http://localhost:PORT`. **Stop** sends `SIGTERM` to that process, after checking that it still owns a listener on that port. This stops the whole process, diff --git a/packages/dev-servers/package.json b/packages/dev-servers/package.json index 42b2ab4..6bb141b 100644 --- a/packages/dev-servers/package.json +++ b/packages/dev-servers/package.json @@ -1,7 +1,7 @@ { "id": "dev-servers", "name": "Development servers", - "version": "1.0.2", + "version": "1.1.0", "description": "Lists your listening TCP ports and their processes, with actions to open localhost or stop a process.", "author": "Seb-GRAF", "repository": "https://github.com/Seb-GRAF/stablebar-packages", diff --git a/packages/dev-servers/scripts/servers.sh b/packages/dev-servers/scripts/servers.sh index 2fce6c7..71ae283 100755 --- a/packages/dev-servers/scripts/servers.sh +++ b/packages/dev-servers/scripts/servers.sh @@ -8,7 +8,14 @@ listeners=$(lsof -nP -a -u "$(id -un)" -iTCP:"$PORTS" -sTCP:LISTEN -Fpcn 2>&1) | fi } -printf '%s' "$listeners" | jq -Rns ' +# Docker and OrbStack publish ports through a helper process, so map host ports to container names. +containers=$(docker ps --format '{{.Names}}\t{{.Ports}}' 2>/dev/null) || containers="" + +printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' + ($containers | split("\n") | map(select(length > 0) | split("\t") | .[0] as $name | + [(.[1] // "") | scan(":([0-9]+)(?:-([0-9]+))?->")] | + map(range(.[0] | tonumber; (.[1] // .[0] | tonumber) + 1) | {key: tostring, value: $name}) + ) | add // [] | from_entries) as $docker | reduce (inputs | split("\n")[]) as $line ({pid: "", process: "", servers: []}; if $line | startswith("p") then .pid = $line[1:] elif $line | startswith("c") then .process = $line[1:] @@ -24,7 +31,7 @@ printf '%s' "$listeners" | jq -Rns ' fields: {hint: (if length == 0 then "No listening ports in this range." else "" end)}, lists: {servers: map({ address: "localhost:\(.port)", - process: "\(.process) · PID \(.pid)", + process: ($docker[.port | tostring] as $c | if $c then "\($c) · container" else "\(.process) · PID \(.pid)" end), link: "http://localhost:\(.port)", stop: ("\"$PACKAGE_DIR/scripts/stop.sh\" " + (.pid | @sh) + " " + (.port | tostring | @sh)) })} From 613f8e446cd6fc044ff0534b7cd0eb3102ab5320 Mon Sep 17 00:00:00 2001 From: Danick Fort Date: Mon, 30 Nov 2026 10:00:18 +0100 Subject: [PATCH 2/5] fix: name containers only on ports the Docker helper owns Matching on the port alone labelled a local listener with a container's name when a container published the same port over UDP, on another host address or through a remote Docker context. --- packages/dev-servers/README.md | 2 +- packages/dev-servers/scripts/servers.sh | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/dev-servers/README.md b/packages/dev-servers/README.md index a8943a5..7550013 100644 --- a/packages/dev-servers/README.md +++ b/packages/dev-servers/README.md @@ -4,7 +4,7 @@ Shows the number of distinct listening TCP ports owned by your user. **Port rang defaults to `3000-9999`. The popup lists each port and process and updates every five seconds. IPv4 and IPv6 sockets from the same process on the same port appear once. Ports that Docker or OrbStack publish show the container's name instead of the helper process, -when `docker` is on your PATH. +when `docker` is on your PATH and its daemon (Docker Desktop or OrbStack) is running. Click an address to open `http://localhost:PORT`. **Stop** sends `SIGTERM` to that process, after checking that it still owns a listener on that port. This stops the whole process, diff --git a/packages/dev-servers/scripts/servers.sh b/packages/dev-servers/scripts/servers.sh index 71ae283..e00a1a1 100755 --- a/packages/dev-servers/scripts/servers.sh +++ b/packages/dev-servers/scripts/servers.sh @@ -9,6 +9,7 @@ listeners=$(lsof -nP -a -u "$(id -un)" -iTCP:"$PORTS" -sTCP:LISTEN -Fpcn 2>&1) | } # Docker and OrbStack publish ports through a helper process, so map host ports to container names. +# shortcut: only Docker Desktop and OrbStack helpers get names; other runtimes (Colima, Podman) keep process · PID. containers=$(docker ps --format '{{.Names}}\t{{.Ports}}' 2>/dev/null) || containers="" printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' @@ -31,7 +32,9 @@ printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' fields: {hint: (if length == 0 then "No listening ports in this range." else "" end)}, lists: {servers: map({ address: "localhost:\(.port)", - process: ($docker[.port | tostring] as $c | if $c then "\($c) · container" else "\(.process) · PID \(.pid)" end), + process: ($docker[.port | tostring] as $c | + if $c and (.process | test("^(OrbStack|com\\.docker)")) then "\($c) · container" + else "\(.process) · PID \(.pid)" end), link: "http://localhost:\(.port)", stop: ("\"$PACKAGE_DIR/scripts/stop.sh\" " + (.pid | @sh) + " " + (.port | tostring | @sh)) })} From 06b8f0da9efe8a980797e302c5c1436c7c18f516 Mon Sep 17 00:00:00 2001 From: Danick Fort Date: Mon, 30 Nov 2026 10:10:27 +0100 Subject: [PATCH 3/5] fix: stop only the container from a container's row Stop sent SIGTERM to the Docker or OrbStack helper, which forwards every container's ports, while the row showed one container's name. Run docker stop on that container instead, and read only TCP entries from docker ps so a UDP publish can't name a TCP port. --- packages/dev-servers/README.md | 2 ++ packages/dev-servers/scripts/servers.sh | 20 +++++++++++--------- packages/dev-servers/scripts/stop.sh | 6 +++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/dev-servers/README.md b/packages/dev-servers/README.md index 7550013..20e67b1 100644 --- a/packages/dev-servers/README.md +++ b/packages/dev-servers/README.md @@ -9,6 +9,8 @@ when `docker` is on your PATH and its daemon (Docker Desktop or OrbStack) is run Click an address to open `http://localhost:PORT`. **Stop** sends `SIGTERM` to that process, after checking that it still owns a listener on that port. This stops the whole process, including any other ports it serves. It does not force-kill processes or stop their supervisors. +On a container's row, **Stop** runs `docker stop` on that container instead, which leaves Docker +and its other containers running. Requires `jq`. The scan uses `lsof` and needs no elevated permissions or network requests. The range can contain non-HTTP services; opening those in a browser may fail. diff --git a/packages/dev-servers/scripts/servers.sh b/packages/dev-servers/scripts/servers.sh index e00a1a1..f4e5ef8 100755 --- a/packages/dev-servers/scripts/servers.sh +++ b/packages/dev-servers/scripts/servers.sh @@ -14,7 +14,7 @@ containers=$(docker ps --format '{{.Names}}\t{{.Ports}}' 2>/dev/null) || contain printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' ($containers | split("\n") | map(select(length > 0) | split("\t") | .[0] as $name | - [(.[1] // "") | scan(":([0-9]+)(?:-([0-9]+))?->")] | + [(.[1] // "") | scan(":([0-9]+)(?:-([0-9]+))?->[0-9-]+/tcp")] | map(range(.[0] | tonumber; (.[1] // .[0] | tonumber) + 1) | {key: tostring, value: $name}) ) | add // [] | from_entries) as $docker | reduce (inputs | split("\n")[]) as $line ({pid: "", process: "", servers: []}; @@ -30,12 +30,14 @@ printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' text: (map(.port) | unique | length | tostring), icon: "server.rack", fields: {hint: (if length == 0 then "No listening ports in this range." else "" end)}, - lists: {servers: map({ - address: "localhost:\(.port)", - process: ($docker[.port | tostring] as $c | - if $c and (.process | test("^(OrbStack|com\\.docker)")) then "\($c) · container" - else "\(.process) · PID \(.pid)" end), - link: "http://localhost:\(.port)", - stop: ("\"$PACKAGE_DIR/scripts/stop.sh\" " + (.pid | @sh) + " " + (.port | tostring | @sh)) - })} + lists: {servers: map( + (if .process | test("^(OrbStack|com\\.docker)") then $docker[.port | tostring] else null end) as $c | + { + address: "localhost:\(.port)", + process: (if $c then "\($c) · container" else "\(.process) · PID \(.pid)" end), + link: "http://localhost:\(.port)", + stop: ("\"$PACKAGE_DIR/scripts/stop.sh\" " + (.pid | @sh) + " " + (.port | tostring | @sh) + + (if $c then " " + ($c | @sh) else "" end)) + } + )} }' diff --git a/packages/dev-servers/scripts/stop.sh b/packages/dev-servers/scripts/stop.sh index bbd1201..88d29cb 100755 --- a/packages/dev-servers/scripts/stop.sh +++ b/packages/dev-servers/scripts/stop.sh @@ -3,7 +3,11 @@ set -euo pipefail pid=$1 port=$2 +container=${3-} -if lsof -nP -a -u "$(id -un)" -p "$pid" -iTCP:"$port" -sTCP:LISTEN -t > /dev/null; then +# The helper process forwards every container's ports, so stop only the container. +if [[ -n $container ]]; then + docker stop "$container" > /dev/null +elif lsof -nP -a -u "$(id -un)" -p "$pid" -iTCP:"$port" -sTCP:LISTEN -t > /dev/null; then kill -TERM "$pid" fi From 13530ecca3371231909f762530df6db8d65dbf39 Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:59:36 +0100 Subject: [PATCH 4/5] fix: stop containers by ID and ask only a local Docker daemon A remote Docker context made the list contact that host every five seconds and could name a local port after a remote container. Read the endpoint first and query it only when it is a unix socket. Stop now passes the container's ID, so a stale row can't stop a newer container that took the name, and it no longer sends SIGTERM to the Docker or OrbStack helper, which forwards every container's ports. --- packages/dev-servers/README.md | 6 ++++-- packages/dev-servers/scripts/servers.sh | 18 +++++++++++------- packages/dev-servers/scripts/stop.sh | 18 +++++++++++++++--- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/dev-servers/README.md b/packages/dev-servers/README.md index 20e67b1..1709047 100644 --- a/packages/dev-servers/README.md +++ b/packages/dev-servers/README.md @@ -4,13 +4,15 @@ Shows the number of distinct listening TCP ports owned by your user. **Port rang defaults to `3000-9999`. The popup lists each port and process and updates every five seconds. IPv4 and IPv6 sockets from the same process on the same port appear once. Ports that Docker or OrbStack publish show the container's name instead of the helper process, -when `docker` is on your PATH and its daemon (Docker Desktop or OrbStack) is running. +when `docker` is on your PATH, its daemon (Docker Desktop or OrbStack) is running, and the +current Docker context points at this Mac. A remote context is never queried. Click an address to open `http://localhost:PORT`. **Stop** sends `SIGTERM` to that process, after checking that it still owns a listener on that port. This stops the whole process, including any other ports it serves. It does not force-kill processes or stop their supervisors. On a container's row, **Stop** runs `docker stop` on that container instead, which leaves Docker -and its other containers running. +and its other containers running. **Stop** never stops the Docker or OrbStack helper itself, +since it forwards the ports of every container. Requires `jq`. The scan uses `lsof` and needs no elevated permissions or network requests. The range can contain non-HTTP services; opening those in a browser may fail. diff --git a/packages/dev-servers/scripts/servers.sh b/packages/dev-servers/scripts/servers.sh index f4e5ef8..c5c1211 100755 --- a/packages/dev-servers/scripts/servers.sh +++ b/packages/dev-servers/scripts/servers.sh @@ -8,14 +8,18 @@ listeners=$(lsof -nP -a -u "$(id -un)" -iTCP:"$PORTS" -sTCP:LISTEN -Fpcn 2>&1) | fi } -# Docker and OrbStack publish ports through a helper process, so map host ports to container names. +# Docker and OrbStack publish ports through a helper process, so map host ports to containers. # shortcut: only Docker Desktop and OrbStack helpers get names; other runtimes (Colima, Podman) keep process · PID. -containers=$(docker ps --format '{{.Names}}\t{{.Ports}}' 2>/dev/null) || containers="" +# Ask only a daemon on this Mac: a remote Docker context would mean a network request every few seconds. +containers="" +if host=$(docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/null) && [[ $host == unix://* ]]; then + containers=$(docker --host "$host" ps --no-trunc --format '{{.ID}}\t{{.Names}}\t{{.Ports}}' 2>/dev/null) || containers="" +fi printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' - ($containers | split("\n") | map(select(length > 0) | split("\t") | .[0] as $name | - [(.[1] // "") | scan(":([0-9]+)(?:-([0-9]+))?->[0-9-]+/tcp")] | - map(range(.[0] | tonumber; (.[1] // .[0] | tonumber) + 1) | {key: tostring, value: $name}) + ($containers | split("\n") | map(select(length > 0) | split("\t") | {id: .[0], name: .[1]} as $container | + [(.[2] // "") | scan(":([0-9]+)(?:-([0-9]+))?->[0-9-]+/tcp")] | + map(range(.[0] | tonumber; (.[1] // .[0] | tonumber) + 1) | {key: tostring, value: $container}) ) | add // [] | from_entries) as $docker | reduce (inputs | split("\n")[]) as $line ({pid: "", process: "", servers: []}; if $line | startswith("p") then .pid = $line[1:] @@ -34,10 +38,10 @@ printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' (if .process | test("^(OrbStack|com\\.docker)") then $docker[.port | tostring] else null end) as $c | { address: "localhost:\(.port)", - process: (if $c then "\($c) · container" else "\(.process) · PID \(.pid)" end), + process: (if $c then "\($c.name) · container" else "\(.process) · PID \(.pid)" end), link: "http://localhost:\(.port)", stop: ("\"$PACKAGE_DIR/scripts/stop.sh\" " + (.pid | @sh) + " " + (.port | tostring | @sh) - + (if $c then " " + ($c | @sh) else "" end)) + + (if $c then " " + ($c.id | @sh) else "" end)) } )} }' diff --git a/packages/dev-servers/scripts/stop.sh b/packages/dev-servers/scripts/stop.sh index 88d29cb..8b6039d 100755 --- a/packages/dev-servers/scripts/stop.sh +++ b/packages/dev-servers/scripts/stop.sh @@ -5,9 +5,21 @@ pid=$1 port=$2 container=${3-} -# The helper process forwards every container's ports, so stop only the container. +# The helper process forwards every container's ports, so stop only the container. Its ID, unlike +# its name, can't reach a newer container that took the name after the list was read. if [[ -n $container ]]; then docker stop "$container" > /dev/null -elif lsof -nP -a -u "$(id -un)" -p "$pid" -iTCP:"$port" -sTCP:LISTEN -t > /dev/null; then - kill -TERM "$pid" + exit fi + +process=$(lsof -nP -a -u "$(id -un)" -p "$pid" -iTCP:"$port" -sTCP:LISTEN -Fc | sed -n 's/^c//p') || exit 0 + +# A helper's row has no container name when docker couldn't be asked; stopping it would cut every container. +case $process in + OrbStack* | com.docker*) + printf '%s forwards the ports of every container, so Stop leaves it running.\n' "$process" >&2 + exit 1 + ;; +esac + +kill -TERM "$pid" From 3fa9d6983026e785a6066efc0238524dc414ee60 Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:08:42 +0100 Subject: [PATCH 5/5] fix: stop a container on the daemon the list was read from Stop sent docker stop to whatever Docker context was active when it was clicked, so switching context after the list was read could miss the container or reach a remote daemon. Pass the local endpoint with the container's ID and stop it there. --- packages/dev-servers/scripts/servers.sh | 4 ++-- packages/dev-servers/scripts/stop.sh | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/dev-servers/scripts/servers.sh b/packages/dev-servers/scripts/servers.sh index c5c1211..2f9701c 100755 --- a/packages/dev-servers/scripts/servers.sh +++ b/packages/dev-servers/scripts/servers.sh @@ -16,7 +16,7 @@ if host=$(docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/nu containers=$(docker --host "$host" ps --no-trunc --format '{{.ID}}\t{{.Names}}\t{{.Ports}}' 2>/dev/null) || containers="" fi -printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' +printf '%s' "$listeners" | jq -Rns --arg containers "$containers" --arg host "$host" ' ($containers | split("\n") | map(select(length > 0) | split("\t") | {id: .[0], name: .[1]} as $container | [(.[2] // "") | scan(":([0-9]+)(?:-([0-9]+))?->[0-9-]+/tcp")] | map(range(.[0] | tonumber; (.[1] // .[0] | tonumber) + 1) | {key: tostring, value: $container}) @@ -41,7 +41,7 @@ printf '%s' "$listeners" | jq -Rns --arg containers "$containers" ' process: (if $c then "\($c.name) · container" else "\(.process) · PID \(.pid)" end), link: "http://localhost:\(.port)", stop: ("\"$PACKAGE_DIR/scripts/stop.sh\" " + (.pid | @sh) + " " + (.port | tostring | @sh) - + (if $c then " " + ($c.id | @sh) else "" end)) + + (if $c then " " + ($c.id | @sh) + " " + ($host | @sh) else "" end)) } )} }' diff --git a/packages/dev-servers/scripts/stop.sh b/packages/dev-servers/scripts/stop.sh index 8b6039d..4744c7e 100755 --- a/packages/dev-servers/scripts/stop.sh +++ b/packages/dev-servers/scripts/stop.sh @@ -4,11 +4,13 @@ set -euo pipefail pid=$1 port=$2 container=${3-} +host=${4-} # The helper process forwards every container's ports, so stop only the container. Its ID, unlike -# its name, can't reach a newer container that took the name after the list was read. +# its name, can't reach a newer container that took the name after the list was read, and the +# daemon the list was read from still answers if the Docker context changed since. if [[ -n $container ]]; then - docker stop "$container" > /dev/null + docker --host "$host" stop "$container" > /dev/null exit fi