File tree 3 files changed +38
-4
lines changed
3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 1
1
_cli_zsh_autocomplete() {
2
-
3
2
local -a opts
4
3
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
5
-
6
4
_describe 'values' opts
7
-
8
5
return
9
6
}
10
7
Original file line number Diff line number Diff line change @@ -520,7 +520,7 @@ EXAMPLES:
520
520
"stage" : {
521
521
Usage : "Add a local file to the storage" ,
522
522
ArgsUsage : "(<local-path> [<path>]|--stdin <path>)" ,
523
- Complete : completeArgsUsage ,
523
+ Complete : completeLocalFile ,
524
524
Flags : []cli.Flag {
525
525
cli.BoolFlag {
526
526
Name : "stdin,i" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package cmd
2
2
3
3
import (
4
4
"fmt"
5
+ "io/ioutil"
6
+ "os"
5
7
"sort"
6
8
"strings"
7
9
@@ -137,6 +139,41 @@ func completeArgsUsage(ctx *cli.Context) {
137
139
}
138
140
}
139
141
142
+ func completeLocalFile (ctx * cli.Context ) {
143
+ if len (os .Args ) >= 2 {
144
+ lastArg := os .Args [len (os .Args )- 2 ]
145
+ cmd := findCurrentCommand (ctx )
146
+ if lastArg != cmd .FullName () {
147
+ return
148
+ }
149
+ }
150
+
151
+ // CAVEAT: We currently do not get partial words from bash/zsh.
152
+ // e.g. "brig stage /us" will pass the following os.Args:
153
+ // ["brig", "stage", "--generate-bash-completion"]
154
+ //
155
+ // Because of that we do no prefix completion right now.
156
+ // We can probably tweak autcomplete/{z,ba}sh_autcomplete to
157
+ // somehow do this, but after 30mins of googling I give up for now.
158
+ //
159
+ // If you read this, I challenge you to do it better.
160
+ dir , err := os .Getwd ()
161
+ if err != nil {
162
+ // silent error.
163
+ return
164
+ }
165
+
166
+ children , err := ioutil .ReadDir (dir )
167
+ if err != nil {
168
+ // silent error.
169
+ return
170
+ }
171
+
172
+ for _ , child := range children {
173
+ fmt .Println (child .Name ())
174
+ }
175
+ }
176
+
140
177
func completeSubcommands (ctx * cli.Context ) {
141
178
if command := findCurrentCommand (ctx ); command != nil {
142
179
for _ , subCmd := range command .Subcommands {
You can’t perform that action at this time.
0 commit comments