diff --git a/cmd/root.go b/cmd/root.go index a8c86f2..050615b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 @@ -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( @@ -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)