feat: case insensitive file complete (closes #104)

insensitive-tab
TorchedSammy 2022-03-14 21:22:10 -04:00
parent b8e0874ab0
commit 7be96504b4
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 21 additions and 1 deletions

View File

@ -2,8 +2,10 @@ package main
import ( import (
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"os" "os"
"unicode"
) )
func fileComplete(query, ctx string, fields []string) []string { func fileComplete(query, ctx string, fields []string) []string {
@ -76,7 +78,7 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) {
func matchPath(path, pref string) ([]string, error) { func matchPath(path, pref string) ([]string, error) {
var entries []string var entries []string
matches, err := filepath.Glob(path + "*") matches, err := filepath.Glob(desensitize(path) + "*")
if err == nil { if err == nil {
args := []string{ args := []string{
"\"", "\\\"", "\"", "\\\"",
@ -108,3 +110,21 @@ func matchPath(path, pref string) ([]string, error) {
return entries, err return entries, err
} }
func desensitize(text string) string {
if runtime.GOOS == "windows" {
return text
}
p := strings.Builder{}
for _, r := range text {
if unicode.IsLetter(r) {
p.WriteString("[" + string(unicode.ToLower(r)) + string(unicode.ToUpper(r)) + "]")
} else {
p.WriteString(string(r))
}
}
return p.String()
}