mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "7486d584658fb557ab7de9a2b49a8a6e2d93ec41" and "4a08ab78377eabbba5a6c2fa254589d7fc0d2f50" have entirely different histories.
7486d58465
...
4a08ab7837
2
Makefile
2
Makefile
|
@ -9,14 +9,12 @@ install:
|
|||
@install -v -d "$(BINDIR)/" && install -m 0755 -v hilbish "$(BINDIR)/hilbish"
|
||||
@mkdir -p "$(LIBDIR)"
|
||||
@cp libs preload.lua .hilbishrc.lua "$(LIBDIR)" -r
|
||||
@echo /usr/bin/hilbish >> /etc/shells
|
||||
@echo "Hilbish Installed"
|
||||
|
||||
uninstall:
|
||||
@rm -vrf \
|
||||
"$(BINDIR)/hilbish" \
|
||||
"$(LIBDIR)"
|
||||
@sed '/\/usr\/bin\/hilbish/d' /etc/shells
|
||||
@echo "Hilbish Uninstalled"
|
||||
|
||||
clean:
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
It is currently in a mostly beta state but is very much usable
|
||||
(I'm using it right now).
|
||||
|
||||
There are still some things missing like pipes but granted that will be
|
||||
added soon. (or you can use dev branch)
|
||||
|
||||
# Links
|
||||
- **[Documentation](https://github.com/Hilbis/Hilbish/wiki)**
|
||||
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package bait
|
||||
|
||||
import (
|
||||
"github.com/chuckpreslar/emission"
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
type Bait struct{}
|
||||
|
||||
func New() Bait {
|
||||
return Bait{}
|
||||
}
|
||||
|
||||
func (b *Bait) Loader(L *lua.LState) int {
|
||||
var exports = map[string]lua.LGFunction{}
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
|
||||
L.Push(mod)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
67
main.go
67
main.go
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
_ "bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
_ "os/exec"
|
||||
|
@ -63,14 +63,12 @@ func main() {
|
|||
}
|
||||
|
||||
homedir, _ := os.UserHomeDir()
|
||||
if _, err := os.Stat(homedir + "/.hilbishrc.lua"); os.IsNotExist(err) {
|
||||
err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating config file")
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating config file")
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
HandleSignals()
|
||||
LuaInit()
|
||||
|
@ -85,7 +83,7 @@ func main() {
|
|||
|
||||
//fmt.Printf(prompt)
|
||||
|
||||
cmdString, err := readline.String(fmtPrompt())
|
||||
cmdString, err := readline.String(prompt)
|
||||
if err == io.EOF {
|
||||
fmt.Println("")
|
||||
break
|
||||
|
@ -96,10 +94,7 @@ func main() {
|
|||
cmdString = strings.TrimSuffix(cmdString, "\n")
|
||||
err = l.DoString(cmdString)
|
||||
|
||||
if err == nil {
|
||||
readline.AddHistory(cmdString)
|
||||
continue
|
||||
}
|
||||
if err == nil { continue }
|
||||
|
||||
cmdArgs := splitInput(cmdString)
|
||||
if len(cmdArgs) == 0 { continue }
|
||||
|
@ -134,49 +129,12 @@ func main() {
|
|||
default:
|
||||
err := execCommand(cmdString)
|
||||
if err != nil {
|
||||
if syntax.IsIncomplete(err) {
|
||||
sb := &strings.Builder{}
|
||||
for {
|
||||
done := StartMultiline(cmdString, sb)
|
||||
if done {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fmtPrompt() string {
|
||||
return prompt
|
||||
}
|
||||
|
||||
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||
if sb.String() == "" { sb.WriteString(prev + "\n") }
|
||||
|
||||
fmt.Printf("... ")
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
cont, err := reader.ReadString('\n')
|
||||
if err == io.EOF {
|
||||
fmt.Println("")
|
||||
return true
|
||||
}
|
||||
|
||||
sb.WriteString(cont)
|
||||
|
||||
err = execCommand(sb.String())
|
||||
if err != nil && syntax.IsIncomplete(err) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func splitInput(input string) []string {
|
||||
quoted := false
|
||||
cmdArgs := []string{}
|
||||
|
@ -207,7 +165,10 @@ func splitInput(input string) []string {
|
|||
func execCommand(cmd string) error {
|
||||
file, err := syntax.NewParser().Parse(strings.NewReader(cmd), "")
|
||||
if err != nil {
|
||||
return err
|
||||
if syntax.IsIncomplete(err) {
|
||||
fmt.Println("incomplete input")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
runner, _ := interp.New(
|
||||
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
|
||||
|
|
Loading…
Reference in New Issue