From 8da2943db006573bb34d8b0863239ee95314f732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 27 Dec 2018 20:08:32 +0100 Subject: [PATCH] zsh: sort the commands to keep a determinist output --- zsh_completions.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/zsh_completions.go b/zsh_completions.go index 889c22e2..e76d6071 100644 --- a/zsh_completions.go +++ b/zsh_completions.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "sort" "strings" ) @@ -81,16 +82,24 @@ func writeLevel(w io.Writer, root *Command, i int) { commands := filterByLevel(root, i) byParent := groupByParent(commands) - for p, c := range byParent { - names := names(c) - fmt.Fprintf(w, " %s)\n", p) + // sort the parents to keep a determinist order + parents := make([]string, len(byParent)) + j := 0 + for parent := range byParent { + parents[j] = parent + j++ + } + sort.StringSlice(parents).Sort() + + for _, parent := range parents { + names := names(byParent[parent]) + fmt.Fprintf(w, " %s)\n", parent) fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " ")) fmt.Fprintln(w, " ;;") } fmt.Fprintln(w, " *)") fmt.Fprintln(w, " _arguments '*: :_files'") fmt.Fprintln(w, " ;;") - } func filterByLevel(c *Command, l int) []*Command {