mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
ignore items with configured substrings
This commit is contained in:
parent
950936b178
commit
9ec03eef45
4 changed files with 39 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||
"github.com/jesseduffield/lazydocker/pkg/i18n"
|
||||
"github.com/jesseduffield/lazydocker/pkg/utils"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
@ -218,7 +219,9 @@ func (c *DockerCommand) RefreshContainersAndServices() error {
|
|||
|
||||
c.Containers = containers
|
||||
c.Services = services
|
||||
c.Services = c.filterOutIgnoredServices(c.Services)
|
||||
c.DisplayContainers = c.filterOutExited(displayContainers)
|
||||
c.DisplayContainers = c.filterOutIgnoredContainers(c.DisplayContainers)
|
||||
c.DisplayContainers = c.sortedContainers(c.DisplayContainers)
|
||||
|
||||
return nil
|
||||
|
|
@ -251,6 +254,22 @@ func (c *DockerCommand) filterOutExited(containers []*Container) []*Container {
|
|||
return toReturn
|
||||
}
|
||||
|
||||
func (c *DockerCommand) filterOutIgnoredContainers(containers []*Container) []*Container {
|
||||
return lo.Filter(containers, func(container *Container, _ int) bool {
|
||||
return !lo.SomeBy(c.Config.UserConfig.Ignore, func(ignore string) bool {
|
||||
return strings.Contains(container.Name, ignore)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (c *DockerCommand) filterOutIgnoredServices(services []*Service) []*Service {
|
||||
return lo.Filter(services, func(service *Service, _ int) bool {
|
||||
return !lo.SomeBy(c.Config.UserConfig.Ignore, func(ignore string) bool {
|
||||
return strings.Contains(service.Name, ignore)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// sortedContainers returns containers sorted by state if c.SortContainersByState is true (follows 1- running, 2- exited, 3- created)
|
||||
// and sorted by name if c.SortContainersByState is false
|
||||
func (c *DockerCommand) sortedContainers(containers []*Container) []*Container {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
|
@ -144,6 +145,12 @@ func (c *DockerCommand) RefreshImages() ([]*Image, error) {
|
|||
}
|
||||
}
|
||||
|
||||
ownImages = lo.Filter(ownImages, func(image *Image, _ int) bool {
|
||||
return !lo.SomeBy(c.Config.UserConfig.Ignore, func(ignore string) bool {
|
||||
return strings.Contains(image.Name, ignore)
|
||||
})
|
||||
})
|
||||
|
||||
noneLabel := "<none>"
|
||||
|
||||
sort.Slice(ownImages, func(i, j int) bool {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ package commands
|
|||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
@ -60,6 +62,12 @@ func (c *DockerCommand) RefreshVolumes() error {
|
|||
}
|
||||
}
|
||||
|
||||
ownVolumes = lo.Filter(ownVolumes, func(volume *Volume, _ int) bool {
|
||||
return !lo.SomeBy(c.Config.UserConfig.Ignore, func(ignore string) bool {
|
||||
return strings.Contains(volume.Name, ignore)
|
||||
})
|
||||
})
|
||||
|
||||
c.Volumes = ownVolumes
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -60,6 +60,11 @@ type UserConfig struct {
|
|||
|
||||
// Replacements determines how we render an item's info
|
||||
Replacements Replacements `yaml:"replacements,omitempty"`
|
||||
|
||||
// For demo purposes: any list item with one of these strings as a substring
|
||||
// will be filtered out and not displayed.
|
||||
// Not documented because it's subject to change
|
||||
Ignore []string `yaml:"ignore,omitempty"`
|
||||
}
|
||||
|
||||
// ThemeConfig is for setting the colors of panels and some text.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue