diff options
| author | Eyal Posener <[email protected]> | 2019-07-05 14:58:49 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2019-07-05 17:29:25 +0300 |
| commit | 29f43e246ec41ee311a0a9bc24b15cb4ece4e513 (patch) | |
| tree | a89a2f4ae80897cb9a1f5f98f702ca2d8210731c /predict_files.go | |
| parent | f71e6baaf2e0d387a847f8e599af7d75be650283 (diff) | |
deprecate match package
Diffstat (limited to 'predict_files.go')
| -rw-r--r-- | predict_files.go | 20 |
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) +} |
