mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
Merge pull request #302 from alexmozzhakov/master
Improvements to autocomplete
This commit is contained in:
commit
5ee7a9cf82
1 changed files with 36 additions and 1 deletions
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/bettercap/bettercap/packets"
|
"github.com/bettercap/bettercap/packets"
|
||||||
|
|
||||||
"github.com/adrianmo/go-nmea"
|
"github.com/adrianmo/go-nmea"
|
||||||
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const HistoryFile = "~/bettercap.history"
|
const HistoryFile = "~/bettercap.history"
|
||||||
|
@ -206,12 +207,21 @@ func (s *Session) setupReadline() error {
|
||||||
|
|
||||||
var appendedOption = strings.Join(parts[1:], " ")
|
var appendedOption = strings.Join(parts[1:], " ")
|
||||||
|
|
||||||
if len(appendedOption) > 0 {
|
if len(appendedOption) > 0 && !containsCapitals(appendedOption) {
|
||||||
tree[name] = append(tree[name], appendedOption)
|
tree[name] = append(tree[name], appendedOption)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
for root, subElems := range tree {
|
||||||
item := readline.PcItem(root)
|
item := readline.PcItem(root)
|
||||||
item.Children = []readline.PrefixCompleterInterface{}
|
item.Children = []readline.PrefixCompleterInterface{}
|
||||||
|
@ -239,6 +249,31 @@ func (s *Session) setupReadline() error {
|
||||||
return err
|
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") {
|
||||||
|
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 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Session) Close() {
|
func (s *Session) Close() {
|
||||||
fmt.Printf("\nStopping modules and cleaning session state ...\n")
|
fmt.Printf("\nStopping modules and cleaning session state ...\n")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue