From 59963add14c7d0134795d4f928efb75b0af1251e Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 5 Mar 2022 08:58:12 -0400 Subject: [PATCH] fix: dont complete binaries in path if complete req starts with file prefix --- rl.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/rl.go b/rl.go index 07ebc59..6d6615a 100644 --- a/rl.go +++ b/rl.go @@ -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