summaryrefslogtreecommitdiff
path: root/predict_files.go
diff options
context:
space:
mode:
Diffstat (limited to 'predict_files.go')
-rw-r--r--predict_files.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/predict_files.go b/predict_files.go
index c8adf7e..c8baec1 100644
--- a/predict_files.go
+++ b/predict_files.go
@@ -5,8 +5,6 @@ import (
"os"
"path/filepath"
"strings"
-
- "github.com/posener/complete/match"
)
// PredictDirs will search for directories in the given started to be typed
@@ -70,7 +68,7 @@ func PredictFilesSet(files []string) PredictFunc {
f = fixPathForm(a.Last, f)
// test matching of file to the argument
- if match.File(f, a.Last) {
+ if matchFile(f, a.Last) {
prediction = append(prediction, f)
}
}
@@ -106,3 +104,19 @@ func listFiles(dir, pattern string, allowFiles bool) []string {
}
return list
}
+
+// MatchFile returns true if prefix can match the file
+func matchFile(file, prefix string) bool {
+ // special case for current directory completion
+ if file == "./" && (prefix == "." || prefix == "") {
+ return true
+ }
+ if prefix == "." && strings.HasPrefix(file, ".") {
+ return true
+ }
+
+ file = strings.TrimPrefix(file, "./")
+ prefix = strings.TrimPrefix(prefix, "./")
+
+ return strings.HasPrefix(file, prefix)
+}