From 29f43e246ec41ee311a0a9bc24b15cb4ece4e513 Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Fri, 5 Jul 2019 14:58:49 +0300 Subject: deprecate match package --- predict_files.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'predict_files.go') 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) +} -- cgit v1.2.3