Compare commits

...

2 Commits

2 changed files with 22 additions and 12 deletions

View File

@ -20,8 +20,13 @@ func newFileHistory() (*fileHistory, error) {
} }
} }
var itms []string itms := []string{""}
for _, l := range strings.Split(string(data), "\n") { lines := strings.Split(string(data), "\n")
for i, l := range lines {
if i == len(lines) - 1 {
println(i, l)
continue
}
itms = append(itms, l) itms = append(itms, l)
} }
f, err := os.OpenFile(defaultHistPath, os.O_RDWR | os.O_CREATE, 0755) f, err := os.OpenFile(defaultHistPath, os.O_RDWR | os.O_CREATE, 0755)

25
rl.go
View File

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