@@ -34,6 +34,17 @@ func (cmd *Command) writeFishCompletionTemplate(w io.Writer) error {
3434 // Add global flags
3535 completions := prepareFishFlags (cmd .Name , cmd )
3636
37+ if cmd .ShellComplete != nil {
38+ var completion strings.Builder
39+ fmt .Fprintf (& completion ,
40+ "complete -c %s -n '%s' -xa '(%s --generate-shell-completion 2>/dev/null)'" ,
41+ cmd .Name ,
42+ fishFlagHelper (cmd .Name , cmd ),
43+ cmd .Name ,
44+ )
45+ completions = append (completions , completion .String ())
46+ }
47+
3748 // Add commands and their flags
3849 completions = append (
3950 completions ,
@@ -72,6 +83,25 @@ func prepareFishCommands(binary string, parent *Command) []string {
7283 }
7384 completions = append (completions , completion .String ())
7485 }
86+
87+ if command .ShellComplete != nil {
88+ var completion strings.Builder
89+ var path []string
90+ lineage := command .Lineage ()
91+ for i := len (lineage ) - 2 ; i >= 0 ; i -- {
92+ path = append (path , lineage [i ].Name )
93+ }
94+
95+ fmt .Fprintf (& completion ,
96+ "complete -c %s -n '%s' -xa '(%s %s --generate-shell-completion 2>/dev/null)'" ,
97+ binary ,
98+ fishFlagHelper (binary , command ),
99+ binary ,
100+ strings .Join (path , " " ),
101+ )
102+ completions = append (completions , completion .String ())
103+ }
104+
75105 completions = append (
76106 completions ,
77107 prepareFishFlags (binary , command )... ,
0 commit comments