diff options
| author | Eyal Posener <[email protected]> | 2017-05-11 00:38:24 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-11 02:16:39 +0300 |
| commit | 72dfe017e9209c1809cfcfcbd9039551fe4d2103 (patch) | |
| tree | 4881f90157f3605fbb488c32e0faae7dff1bc818 /match/file.go | |
| parent | 1c743d8c0b8235ea2dbf0856987f8bd5b77a0042 (diff) | |
Improve files and directories completion
Diffstat (limited to 'match/file.go')
| -rw-r--r-- | match/file.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/match/file.go b/match/file.go index c972ce0..0b554ce 100644 --- a/match/file.go +++ b/match/file.go @@ -1,7 +1,6 @@ package match import ( - "path/filepath" "strings" ) @@ -15,16 +14,13 @@ func (a File) String() string { // Match returns true if prefix's abs path prefixes a's abs path func (a File) Match(prefix string) bool { - full, err := filepath.Abs(string(a)) - if err != nil { - return false - } - prefixFull, err := filepath.Abs(prefix) - if err != nil { - return false + + // special case for current directory completion + if a == "./" && (prefix == "." || prefix == "") { + return true } - // if the file has the prefix as prefix, - // but we don't want to show too many files, so, if it is in a deeper directory - omit it. - return strings.HasPrefix(full, prefixFull) && (full == prefixFull || !strings.Contains(full[len(prefixFull)+1:], "/")) + cmp := strings.TrimPrefix(string(a), "./") + prefix = strings.TrimPrefix(prefix, "./") + return strings.HasPrefix(cmp, prefix) } |
