From 472288c81b3ad48dc86e5a8538c11c7a18e6a604 Mon Sep 17 00:00:00 2001 From: Robert Verst Date: Wed, 19 May 2021 19:14:32 +0200 Subject: [PATCH] Add user config to change the sort order of tags --- docs/Config.md | 1 + pkg/commands/loading_tags.go | 11 +++++++++-- pkg/config/user_config.go | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index c37747dbe..c322f2e87 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -44,6 +44,7 @@ gui: showRandomTip: true showCommandLog: true commandLogSize: 8 + sortTagsDescending: false # sort order for tags git: paging: colorArg: always diff --git a/pkg/commands/loading_tags.go b/pkg/commands/loading_tags.go index 9ed350fd5..21925f184 100644 --- a/pkg/commands/loading_tags.go +++ b/pkg/commands/loading_tags.go @@ -46,11 +46,18 @@ func (c *GitCommand) GetTags() ([]*models.Tag, error) { // now lets sort our tags by name numerically re := regexp.MustCompile(semverRegex) + sortAsc := !c.Config.GetUserConfig().Gui.SortTagsDescending // the reason this is complicated is because we're both sorting alphabetically // and when we're dealing with semver strings sort.Slice(tags, func(i, j int) bool { - a := tags[i].Name - b := tags[j].Name + var a, b string + if sortAsc { + a = tags[i].Name + b = tags[j].Name + } else { + b = tags[i].Name + a = tags[j].Name + } matchA := re.FindStringSubmatch(a) matchB := re.FindStringSubmatch(b) diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index cf193011b..528830874 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -39,6 +39,7 @@ type GuiConfig struct { ShowRandomTip bool `yaml:"showRandomTip"` ShowCommandLog bool `yaml:"showCommandLog"` CommandLogSize int `yaml:"commandLogSize"` + SortTagsDescending bool `yaml:"sortTagsDescending"` } type ThemeConfig struct { @@ -307,6 +308,7 @@ func GetDefaultConfig() *UserConfig { ShowFileTree: false, ShowRandomTip: true, CommandLogSize: 8, + SortTagsDescending: false, }, Git: GitConfig{ Paging: PagingConfig{