Skip to content

Commit

Permalink
Merge pull request #375 from jesseduffield/sort-volumes-by-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield authored Oct 10, 2022
2 parents 0e0997d + ec8dfba commit 26858c3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/commands/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down

0 comments on commit 26858c3

Please sign in to comment.