2017-05-07 11:53:55 -05:00
|
|
|
package match
|
|
|
|
|
2017-05-11 12:48:40 -05:00
|
|
|
import "strings"
|
2017-05-07 11:53:55 -05:00
|
|
|
|
2017-05-11 12:48:40 -05:00
|
|
|
// File returns true if prefix can match the file
|
|
|
|
func File(file, prefix string) bool {
|
2017-05-10 16:38:24 -05:00
|
|
|
// special case for current directory completion
|
2017-05-11 12:48:40 -05:00
|
|
|
if file == "./" && (prefix == "." || prefix == "") {
|
2017-05-10 16:38:24 -05:00
|
|
|
return true
|
2017-05-07 11:53:55 -05:00
|
|
|
}
|
2017-05-15 15:52:04 -05:00
|
|
|
if prefix == "." && strings.HasPrefix(file, ".") {
|
|
|
|
return true
|
|
|
|
}
|
2017-05-07 11:53:55 -05:00
|
|
|
|
2017-05-11 12:48:40 -05:00
|
|
|
file = strings.TrimPrefix(file, "./")
|
2017-05-10 16:38:24 -05:00
|
|
|
prefix = strings.TrimPrefix(prefix, "./")
|
2017-05-15 15:52:04 -05:00
|
|
|
|
2017-05-11 12:48:40 -05:00
|
|
|
return strings.HasPrefix(file, prefix)
|
2017-05-07 11:53:55 -05:00
|
|
|
}
|