mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
Adding search for caplets into autocomplete (only /caplets/ will be
searched recursively)
This commit is contained in:
parent
7e952865cc
commit
17d931a074
1 changed files with 27 additions and 0 deletions
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/bettercap/bettercap/packets"
|
||||
|
||||
"github.com/adrianmo/go-nmea"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
const HistoryFile = "~/bettercap.history"
|
||||
|
@ -212,6 +213,15 @@ func (s *Session) setupReadline() error {
|
|||
}
|
||||
}
|
||||
|
||||
searchForCap("./", tree, false)
|
||||
searchForCap("./caplets/", tree, true)
|
||||
capspath := core.Trim(os.Getenv("CAPSPATH"))
|
||||
var paths []string
|
||||
paths = append(paths, core.SepSplit(capspath, ":")...)
|
||||
for _, path := range paths {
|
||||
searchForCap(path, tree, false)
|
||||
}
|
||||
|
||||
for root, subElems := range tree {
|
||||
item := readline.PcItem(root)
|
||||
item.Children = []readline.PrefixCompleterInterface{}
|
||||
|
@ -239,6 +249,23 @@ func (s *Session) setupReadline() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func searchForCap(path string, tree map[string][]string, recursive bool) {
|
||||
_searchForCap(path, tree, recursive, path)
|
||||
}
|
||||
|
||||
func _searchForCap(path string, tree map[string][]string, recursive bool, prefix string) {
|
||||
subFiles, _ := ioutil.ReadDir(path)
|
||||
|
||||
for _, subF := range subFiles {
|
||||
if strings.HasSuffix(subF.Name(), ".cap") {
|
||||
fmt.Println(path + strings.Replace(subF.Name(), ".cap", "", -1))
|
||||
tree[strings.TrimPrefix(path, prefix)+strings.Replace(subF.Name(), ".cap", "", -1)] = []string{}
|
||||
} else if subF.IsDir() && recursive {
|
||||
_searchForCap(path+subF.Name()+"/", tree, true, prefix)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func containsCapitals(s string) bool {
|
||||
for _, ch := range s {
|
||||
if ch < 133 && ch > 101 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue