follow directories for file name completion
This commit is contained in:
parent
bc41ed7469
commit
d9583187e5
36
comp.go
36
comp.go
@ -96,23 +96,45 @@ func matchExec(s string) (matches []string, longest string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func matchFile(s string) (matches []string, longest string) {
|
func matchFile(s string) (matches []string, longest string) {
|
||||||
wd, err := os.Getwd()
|
dir := strings.Replace(s, "~", envHome, -1)
|
||||||
if err != nil {
|
|
||||||
log.Printf("getting current directory: %s", err)
|
if !path.IsAbs(dir) {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
dir = wd + "/" + dir
|
||||||
}
|
}
|
||||||
|
|
||||||
fi, err := ioutil.ReadDir(wd)
|
dir = path.Dir(dir)
|
||||||
|
|
||||||
|
fi, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading directory: %s", err)
|
log.Printf("reading directory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fi {
|
for _, f := range fi {
|
||||||
if strings.HasPrefix(f.Name(), s) {
|
f, err := os.Stat(path.Join(dir, f.Name()))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting file information: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, last := path.Split(s)
|
||||||
|
if strings.HasPrefix(f.Name(), last) {
|
||||||
|
name := f.Name()
|
||||||
|
if isRoot(s) || path.Base(s) != s {
|
||||||
|
name = path.Join(path.Dir(s), f.Name())
|
||||||
|
}
|
||||||
matches = append(matches, f.Name())
|
matches = append(matches, f.Name())
|
||||||
if longest != "" {
|
if longest != "" {
|
||||||
longest = matchLongest(longest, f.Name())
|
longest = matchLongest(longest, name)
|
||||||
} else {
|
} else {
|
||||||
longest = f.Name() + " "
|
if f.Mode().IsRegular() {
|
||||||
|
longest = name + " "
|
||||||
|
} else {
|
||||||
|
longest = name + "/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user