summaryrefslogtreecommitdiff
path: root/match/file.go
blob: 0b554ce96fff2c8505ff46a8ffe93044888c023d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package match

import (
	"strings"
)

// File is a file name Matcher, if the last word can prefix the
// File path, there is a possible match
type File string

func (a File) String() string {
	return string(a)
}

// Match returns true if prefix's abs path prefixes a's abs path
func (a File) Match(prefix string) bool {

	// special case for current directory completion
	if a == "./" && (prefix == "." || prefix == "") {
		return true
	}

	cmp := strings.TrimPrefix(string(a), "./")
	prefix = strings.TrimPrefix(prefix, "./")
	return strings.HasPrefix(cmp, prefix)
}