2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-04-02 03:33:22 +00:00

fix: dont complete binaries in path if complete req starts with file prefix

This commit is contained in:
TorchedSammy 2022-03-05 08:58:12 -04:00
parent 88fd6f01b9
commit 59963add14
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD

25
rl.go
View File

@ -60,19 +60,24 @@ func newLineReader(prompt string) *lineReader {
ctx = aliases.Resolve(ctx)
if len(fields) == 1 {
fileCompletions := fileComplete(query, ctx, fields)
if len(fileCompletions) != 0 {
for _, f := range fileCompletions {
name := strings.Replace(query + f, "~", curuser.HomeDir, 1)
if info, err := os.Stat(name); err == nil && info.Mode().Perm() & 0100 == 0 {
continue
prefixes := []string{"./", "../", "/", "~/"}
for _, prefix := range prefixes {
if strings.HasPrefix(query, prefix) {
fileCompletions := fileComplete(query, ctx, fields)
if len(fileCompletions) != 0 {
for _, f := range fileCompletions {
name := strings.Replace(query + f, "~", curuser.HomeDir, 1)
if info, err := os.Stat(name); err == nil && info.Mode().Perm() & 0100 == 0 {
continue
}
completions = append(completions, f)
}
compGroup[0].Suggestions = completions
}
completions = append(completions, f)
return "", compGroup
}
compGroup[0].Suggestions = completions
return "", compGroup
}
// filter out executables, but in path
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
// print dir to stderr for debugging