@@ -46,10 +46,15 @@ sub main {
46
46
if ($cmd eq " bash" ) {
47
47
generate_bash(\@list , \@subdir_cmds , \@options );
48
48
}
49
- else {
49
+ elsif ( $cmd eq " zsh " ) {
50
50
generate_zsh(\@list , \@subdir_cmds , \@options );
51
51
}
52
-
52
+ elsif ($cmd eq " fish" ) {
53
+ generate_fish(\@list , \@subdir_cmds , \@options );
54
+ }
55
+ else {
56
+ die " Unknown shell: $cmd " ;
57
+ }
53
58
}
54
59
55
60
sub generate_zsh {
@@ -139,6 +144,68 @@ sub generate_zsh {
139
144
...
140
145
}
141
146
147
+ sub generate_fish {
148
+ my ($list , $subdir_cmds , $options ) = @_ ;
149
+
150
+ print <<'...' ;
151
+ # DO NOT EDIT. This file generated by pkg/bin/generate-completion.pl.
152
+
153
+ function __fish_git_subrepo_subdirs
154
+ git subrepo status -q
155
+ end
156
+
157
+ complete -c git-subrepo -f
158
+ ...
159
+
160
+ # Add subcommands
161
+ print " complete -c git-subrepo -n '__fish_use_subcommand' -a '" , join (" " , @$list ), " '\n " ;
162
+
163
+ # Add options
164
+ for my $opt (@$options ) {
165
+ my $keys = $opt -> {keys };
166
+ my $desc = $opt -> {desc };
167
+ $desc =~ s / '/ '"'"'/ g ;
168
+
169
+ my @short_keys = grep { length $_ == 1 } @$keys ;
170
+ my @long_keys = grep { length $_ > 1 } @$keys ;
171
+ my $arg = $opt -> {arg } ? " -r" : " " ;
172
+
173
+ if (@short_keys && @long_keys ) {
174
+ # Has both short and long options
175
+ for my $i (0..$#long_keys ) {
176
+ my $short = $short_keys [$i ] // ' ' ;
177
+ my $long = $long_keys [$i ];
178
+ if ($short ) {
179
+ print " complete -c git-subrepo -l $long -s $short -d '$desc '$arg \n " ;
180
+ } else {
181
+ print " complete -c git-subrepo -l $long -d '$desc '$arg \n " ;
182
+ }
183
+ }
184
+ } else {
185
+ # Only short or only long options
186
+ for my $key (@$keys ) {
187
+ if (length $key == 1) {
188
+ print " complete -c git-subrepo -s $key -d '$desc '$arg \n " ;
189
+ } else {
190
+ print " complete -c git-subrepo -l $key -d '$desc '$arg \n " ;
191
+ }
192
+ }
193
+ }
194
+ }
195
+
196
+ # Add subdir commands completion
197
+ for my $cmd (@$subdir_cmds ) {
198
+ print <<"..." ;
199
+ complete -c git-subrepo -n '__fish_git_using_command $cmd ' -a '(__fish_git_subrepo_subdirs)'
200
+ ...
201
+ }
202
+
203
+ # Special handling for clone command which add folders and git remotes
204
+ print <<'...' ;
205
+ complete -c git-subrepo -F -n '__fish_git_using_command clone' -a '(__fish_git_remotes)' -d 'Repository to clone from'
206
+ ...
207
+ }
208
+
142
209
sub generate_bash {
143
210
144
211
my ($list , $subdir_cmds , $options , $complete_fetch_limit ) = @_ ;
0 commit comments