Skip to content

Commit

Permalink
Merge pull request #1 from obvionaoe/implement-sorting
Browse files Browse the repository at this point in the history
Implement profile sorting
  • Loading branch information
obvionaoe authored May 2, 2024
2 parents e033143 + f5b300a commit f3ad85c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ THE SOFTWARE.
package cmd

import (
"cmp"
"github.com/spf13/cobra"
"log"
"os"
"slices"
"strings"
)

var (
browser string
sort bool
rofiCmd string
browser string
sortProfiles bool
rofiCmd string
)

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -60,10 +63,10 @@ func init() {
"The browser to use",
)
rootCmd.Flags().BoolVarP(
&sort,
&sortProfiles,
"sort",
"s",
true,
false,
"Sort the profiles alphabetically",
)
rootCmd.Flags().StringVarP(
Expand Down Expand Up @@ -93,6 +96,12 @@ func run(cmd *cobra.Command, args []string) {
log.Fatal(err)
}

if sortProfiles {
slices.SortFunc(profiles, func(a, b string) int {
return cmp.Compare(strings.ToLower(a), strings.ToLower(b))
})
}

selectedProfile, err := runRofi(profiles)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit f3ad85c

Please sign in to comment.