From ec8dfbac06f12b8d75598354b0f28986ad30c02a Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 10 Oct 2022 13:45:25 -0700 Subject: [PATCH] sort volumes first on whether they have labels and secondly on name --- pkg/commands/volume.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/commands/volume.go b/pkg/commands/volume.go index af44e075a..75419915e 100644 --- a/pkg/commands/volume.go +++ b/pkg/commands/volume.go @@ -36,7 +36,16 @@ func (c *DockerCommand) RefreshVolumes() error { ownVolumes := make([]*Volume, len(volumes)) + // we're sorting these volumes based on whether they have labels defined, + // because those are the ones you typically care about. + // Within that, we also sort them alphabetically sort.Slice(volumes, func(i, j int) bool { + if len(volumes[i].Labels) == 0 && len(volumes[j].Labels) > 0 { + return false + } + if len(volumes[i].Labels) > 0 && len(volumes[j].Labels) == 0 { + return true + } return volumes[i].Name < volumes[j].Name })