@@ -34,6 +34,18 @@ 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 %s 2>/dev/null)'" ,
41+ cmd .Name ,
42+ fishFlagHelper (cmd .Name , cmd ),
43+ cmd .Name ,
44+ completionFlag ,
45+ )
46+ completions = append (completions , completion .String ())
47+ }
48+
3749 // Add commands and their flags
3850 completions = append (
3951 completions ,
@@ -72,6 +84,26 @@ func prepareFishCommands(binary string, parent *Command) []string {
7284 }
7385 completions = append (completions , completion .String ())
7486 }
87+
88+ if command .ShellComplete != nil {
89+ var completion strings.Builder
90+ var path []string
91+ lineage := command .Lineage ()
92+ for i := len (lineage ) - 2 ; i >= 0 ; i -- {
93+ path = append (path , lineage [i ].Name )
94+ }
95+
96+ fmt .Fprintf (& completion ,
97+ "complete -c %s -n '%s' -xa '(%s %s %s 2>/dev/null)'" ,
98+ binary ,
99+ fishFlagHelper (binary , command ),
100+ binary ,
101+ strings .Join (path , " " ),
102+ completionFlag ,
103+ )
104+ completions = append (completions , completion .String ())
105+ }
106+
75107 completions = append (
76108 completions ,
77109 prepareFishFlags (binary , command )... ,
0 commit comments