mirror of https://github.com/Hilbis/Hilbish
Compare commits
5 Commits
3c4351a8fe
...
885c54ed3f
Author | SHA1 | Date |
---|---|---|
sammy | 885c54ed3f | |
sammy | cd96ac86ac | |
sammy | 21e6ff8055 | |
sammy | a9c5b4eea1 | |
sammy | c393080a2e |
|
@ -18,4 +18,3 @@ bait.catch('command.exit', function(code)
|
||||||
doPrompt(code ~= 0)
|
doPrompt(code ~= 0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--hook("tab complete", function ())
|
|
||||||
|
|
3
lua.go
3
lua.go
|
@ -53,7 +53,8 @@ func LuaInit(confpath string) {
|
||||||
.. ';./libs/?/init.lua;./?/init.lua;./?/?.lua'
|
.. ';./libs/?/init.lua;./?/init.lua;./?/?.lua'
|
||||||
.. ';/usr/share/hilbish/libs/?/init.lua;'
|
.. ';/usr/share/hilbish/libs/?/init.lua;'
|
||||||
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/init.lua;'
|
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/init.lua;'
|
||||||
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua'
|
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua;'
|
||||||
|
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'
|
||||||
`)
|
`)
|
||||||
|
|
||||||
err := l.DoFile("/usr/share/hilbish/preload.lua")
|
err := l.DoFile("/usr/share/hilbish/preload.lua")
|
||||||
|
|
29
main.go
29
main.go
|
@ -4,10 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"syscall"
|
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
"bufio"
|
|
||||||
"io"
|
"io"
|
||||||
hooks "hilbish/golibs/bait"
|
hooks "hilbish/golibs/bait"
|
||||||
|
|
||||||
|
@ -17,7 +15,7 @@ import (
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "0.3.1"
|
const version = "0.3.2"
|
||||||
var l *lua.LState
|
var l *lua.LState
|
||||||
// User's prompt, this will get set when lua side is initialized
|
// User's prompt, this will get set when lua side is initialized
|
||||||
var prompt string
|
var prompt string
|
||||||
|
@ -29,6 +27,7 @@ var commands = map[string]bool{}
|
||||||
var aliases = map[string]string{}
|
var aliases = map[string]string{}
|
||||||
var bait hooks.Bait
|
var bait hooks.Bait
|
||||||
var homedir string
|
var homedir string
|
||||||
|
var running bool
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
homedir, _ = os.UserHomeDir()
|
homedir, _ = os.UserHomeDir()
|
||||||
|
@ -89,13 +88,14 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleSignals()
|
go HandleSignals()
|
||||||
LuaInit(*configflag)
|
LuaInit(*configflag)
|
||||||
|
|
||||||
readline.Completer = readline.FilenameCompleter
|
readline.Completer = readline.FilenameCompleter
|
||||||
readline.LoadHistory(homedir + "/.hilbish-history")
|
readline.LoadHistory(homedir + "/.hilbish-history")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
running = false
|
||||||
input, err := readline.String(fmtPrompt())
|
input, err := readline.String(fmtPrompt())
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
// Exit if user presses ^D (ctrl + d)
|
// Exit if user presses ^D (ctrl + d)
|
||||||
|
@ -117,6 +117,7 @@ func main() {
|
||||||
if err != nil || !strings.HasSuffix(input, "\\") { break }
|
if err != nil || !strings.HasSuffix(input, "\\") { break }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
running = true
|
||||||
RunInput(input)
|
RunInput(input)
|
||||||
|
|
||||||
termwidth, _, err := term.GetSize(0)
|
termwidth, _, err := term.GetSize(0)
|
||||||
|
@ -126,12 +127,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ContinuePrompt(prev string) (string, error) {
|
func ContinuePrompt(prev string) (string, error) {
|
||||||
fmt.Print(multilinePrompt)
|
cont, err := readline.String(multilinePrompt)
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
|
|
||||||
// TODO: use readline here?
|
|
||||||
cont, err := reader.ReadString('\n')
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -170,9 +166,14 @@ func fmtPrompt() string {
|
||||||
// do i even have to say
|
// do i even have to say
|
||||||
func HandleSignals() {
|
func HandleSignals() {
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt)
|
||||||
go func() {
|
|
||||||
<-c
|
for range c {
|
||||||
}()
|
if !running {
|
||||||
|
fmt.Println(" // interrupt")
|
||||||
|
readline.ReplaceLine("", 0)
|
||||||
|
readline.RefreshLine()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue