added shell tab complete
This commit is contained in:
parent
44beab651c
commit
d5edb2bad2
4 changed files with 125 additions and 4 deletions
12
cmd/shs.go
12
cmd/shs.go
|
|
@ -20,10 +20,12 @@ package main
|
|||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"strings"
|
||||
"strconv"
|
||||
"github.com/peterh/liner"
|
||||
"gitlab.com/whom/shs/ast"
|
||||
"gitlab.com/whom/shs/log"
|
||||
"gitlab.com/whom/shs/util"
|
||||
"gitlab.com/whom/shs/config"
|
||||
)
|
||||
|
||||
|
|
@ -105,6 +107,10 @@ func main() {
|
|||
defer line.Close()
|
||||
|
||||
line.SetCtrlCAborts(true)
|
||||
line.SetCompleter(func(line string) (c []string) {
|
||||
strtoks := strings.Split(line, " ")
|
||||
return util.ShellCompleter(strtoks[len(strtoks) - 1], vars, funcs)
|
||||
})
|
||||
|
||||
var histFile *os.File
|
||||
var err error
|
||||
|
|
@ -134,12 +140,10 @@ func main() {
|
|||
text, err := line.Prompt(prompt)
|
||||
if err != nil && err != liner.ErrPromptAborted{
|
||||
log.Log(log.ERR, "couldnt read user input: " + err.Error(), "repl")
|
||||
continue
|
||||
}
|
||||
|
||||
if !no_hist {
|
||||
line.WriteHistory(histFile)
|
||||
}
|
||||
|
||||
line.AppendHistory(text)
|
||||
userInput := ast.Lex(text)
|
||||
if userInput == nil {
|
||||
// errors handled in Lex
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue