summaryrefslogtreecommitdiff
path: root/match/file.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-11 02:20:27 +0300
committerGitHub <[email protected]>2017-05-11 02:20:27 +0300
commitdd2171d085ef5957a1c5c0794d6007822e47849b (patch)
tree4881f90157f3605fbb488c32e0faae7dff1bc818 /match/file.go
parent1c743d8c0b8235ea2dbf0856987f8bd5b77a0042 (diff)
parent72dfe017e9209c1809cfcfcbd9039551fe4d2103 (diff)
Merge pull request #11 from posener/files-complete
Improve files and directories completion
Diffstat (limited to 'match/file.go')
-rw-r--r--match/file.go18
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)
}