mirror of https://github.com/Hilbis/Hilbish
feat: case insensitive file complete (closes #104)
parent
b8e0874ab0
commit
7be96504b4
22
complete.go
22
complete.go
|
@ -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()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue