mirror of https://github.com/rwxrob/bonzai
Add directories to comp.File completer
parent
2f1befcb6f
commit
a3a454350a
@ -0,0 +1,26 @@
|
||||
// Copyright 2022 Robert S. Muhlestein.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package comp
|
||||
|
||||
import (
|
||||
"github.com/rwxrob/bonzai/filter"
|
||||
"github.com/rwxrob/bonzai/util"
|
||||
)
|
||||
|
||||
// File returns all file names for the directory and file prefix
|
||||
// passed. If nothing is passed assumes the current working directory.
|
||||
func File(x Command, args ...string) []string {
|
||||
match := ""
|
||||
dir := "."
|
||||
|
||||
if len(args) > 0 {
|
||||
match = args[0]
|
||||
}
|
||||
|
||||
list := []string{}
|
||||
list = append(list, util.Files(dir)...)
|
||||
list = filter.HasPrefix(list, match)
|
||||
return list
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
// Copyright 2022 Robert S. Muhlestein.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package comp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/rwxrob/bonzai/comp"
|
||||
)
|
||||
|
||||
func ExampleFile() {
|
||||
os.Chdir("testdata/file")
|
||||
defer os.Chdir("../..")
|
||||
fmt.Println(comp.File(nil))
|
||||
fmt.Println(comp.File(nil, "b"))
|
||||
fmt.Println(comp.File(nil, "blah"))
|
||||
fmt.Println(comp.File(nil, "blah/"))
|
||||
//Output:
|
||||
// [bar/ blah/ come/ foo/ other/]
|
||||
// [bar/ blah/]
|
||||
// [blah/]
|
||||
// [dir1/ dir2/ file1 file2]
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// Copyright 2022 Robert S. Muhlestein.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package comp
|
||||
|
||||
import (
|
||||
"github.com/rwxrob/bonzai/filter"
|
||||
"github.com/rwxrob/bonzai/util"
|
||||
)
|
||||
|
||||
// Files returns all file names for the directory and file prefix
|
||||
// passed. If nothing is passed assumes the current working directory.
|
||||
func Files(x Command, args ...string) []string {
|
||||
match := ""
|
||||
|
||||
if args != nil && len(args) > 0 {
|
||||
match = args[0]
|
||||
}
|
||||
|
||||
list := []string{}
|
||||
|
||||
// TODO if file separators detected, drill down to the proper
|
||||
// directory then check the leaf as the prefix of files
|
||||
|
||||
list = append(list, util.Files(match)...)
|
||||
|
||||
return filter.HasPrefix(list, match)
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2022 Robert S. Muhlestein.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package comp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/rwxrob/bonzai/comp"
|
||||
)
|
||||
|
||||
func ExampleFiles() {
|
||||
os.Chdir("testdata/files")
|
||||
defer os.Chdir("../..")
|
||||
fmt.Println(comp.Files(nil))
|
||||
//Output:
|
||||
// [bar blah come foo other]
|
||||
}
|
Loading…
Reference in New Issue