summaryrefslogtreecommitdiff
path: root/predict_files.go
diff options
context:
space:
mode:
Diffstat (limited to 'predict_files.go')
-rw-r--r--predict_files.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/predict_files.go b/predict_files.go
index 8ad5368..fe70c97 100644
--- a/predict_files.go
+++ b/predict_files.go
@@ -25,9 +25,35 @@ func PredictFiles(pattern string) Predictor {
}
func files(pattern string, allowFiles bool) PredictFunc {
+
+ // search for files according to arguments,
+ // if only one directory has matched the result, search recursively into
+ // this directory to give more results.
return func(a Args) (prediction []string) {
- prediction = predictFiles(a.Last, pattern, allowFiles)
- return
+ last := a.Last
+ for {
+
+ prediction = predictFiles(last, pattern, allowFiles)
+
+ // if the number of prediction is not 1, we either have many results or
+ // have no results, so we return it.
+ if len(prediction) != 1 {
+ return
+ }
+
+ // if the result is only one item, we might want to recursively check
+ // for more accurate results.
+ if prediction[0] == last { // avoid loop forever
+ return
+ }
+
+ // only try deeper, if the one item is a directory
+ if stat, err := os.Stat(prediction[0]); err != nil || !stat.IsDir() {
+ return
+ }
+
+ last = prediction[0]
+ }
}
}