feat(docker): add environment display mode with container listing and filter support#7434
feat(docker): add environment display mode with container listing and filter support#7434Lurchfresser wants to merge 5 commits intoJanDeDobbeleer:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an environment display_mode to the Docker CLI segment to surface running container information (via docker ps) and exposes new configuration options for command aliasing and filtering.
Changes:
- Added
environmentdisplay mode to the Docker segment, including parsingdocker ps --formatoutput into a.Containerstemplate property. - Extended config/schema to support
docker_commandandfilteroptions. - Updated segment docs to document the new mode and properties, and added tests for environment mode behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| website/docs/segments/cli/docker.mdx | Documents environment mode and new template properties/options. |
| themes/schema.json | Extends Docker segment schema with environment, docker_command, and filter. |
| src/segments/docker.go | Implements environment mode and container listing/parsing. |
| src/segments/docker_test.go | Adds test coverage for environment mode enablement and parsing. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| ## What | ||
|
|
||
| Display the current [Docker][docker] context. Will not be active when using the default context. | ||
| Display the current [Docker][docker] context, or a list of running containers when `display_mode` is set to `environment`. |
There was a problem hiding this comment.
The updated “What” description no longer mentions that in context mode the segment is disabled when the active Docker context is default (the code still explicitly ignores default). Please update the docs to reflect that behavior so users don’t expect the segment to show in the default context.
| containers, err := d.fetchContainers() | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| d.Containers = containers | ||
|
|
||
| return len(d.Containers) > 0 |
There was a problem hiding this comment.
environment mode currently enables the segment only when at least one container is returned (len(d.Containers) > 0). This conflicts with the PR description (“active as long as the docker command exists”) and makes it impossible to render a “0 running” state. Please align the behavior (or docs) by either enabling the segment whenever the command exists (and leaving .Containers empty), or updating the description to match the current behavior.
Prerequisites
Description
Added display_mode environment to the docker segment. When this displaymode is used, the block is active as long as the docker command exists.
If this display mode is chosen, docker ps is executed and the output is parsed and supplied in a list.
The user can add filters according to cli-spec.
The user can also provide an alias for the docker command
I did not change code for the other display_modes and did not change the template, to not break existing configs.