mirror of https://github.com/Hilbis/Hilbish
Compare commits
11 Commits
4a08ab7837
...
7486d58465
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 7486d58465 | |
TorchedSammy | aea035fe41 | |
TorchedSammy | c5fa238156 | |
devins2518 | e4218a135a | |
devins2518 | eeafd1e5cf | |
TorchedSammy | deb1bc8a5e | |
TorchedSammy | 1c1ec87612 | |
TorchedSammy | 972c6e44b3 | |
TorchedSammy | d3bd47963d | |
TorchedSammy | bad357af48 | |
TorchedSammy | e4c3445f59 |
2
Makefile
2
Makefile
|
@ -9,12 +9,14 @@ install:
|
||||||
@install -v -d "$(BINDIR)/" && install -m 0755 -v hilbish "$(BINDIR)/hilbish"
|
@install -v -d "$(BINDIR)/" && install -m 0755 -v hilbish "$(BINDIR)/hilbish"
|
||||||
@mkdir -p "$(LIBDIR)"
|
@mkdir -p "$(LIBDIR)"
|
||||||
@cp libs preload.lua .hilbishrc.lua "$(LIBDIR)" -r
|
@cp libs preload.lua .hilbishrc.lua "$(LIBDIR)" -r
|
||||||
|
@echo /usr/bin/hilbish >> /etc/shells
|
||||||
@echo "Hilbish Installed"
|
@echo "Hilbish Installed"
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@rm -vrf \
|
@rm -vrf \
|
||||||
"$(BINDIR)/hilbish" \
|
"$(BINDIR)/hilbish" \
|
||||||
"$(LIBDIR)"
|
"$(LIBDIR)"
|
||||||
|
@sed '/\/usr\/bin\/hilbish/d' /etc/shells
|
||||||
@echo "Hilbish Uninstalled"
|
@echo "Hilbish Uninstalled"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
It is currently in a mostly beta state but is very much usable
|
It is currently in a mostly beta state but is very much usable
|
||||||
(I'm using it right now).
|
(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
|
# Links
|
||||||
- **[Documentation](https://github.com/Hilbis/Hilbish/wiki)**
|
- **[Documentation](https://github.com/Hilbis/Hilbish/wiki)**
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
_ "os/exec"
|
_ "os/exec"
|
||||||
|
@ -63,12 +63,14 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
homedir, _ := os.UserHomeDir()
|
homedir, _ := os.UserHomeDir()
|
||||||
err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644)
|
if _, err := os.Stat(homedir + "/.hilbishrc.lua"); os.IsNotExist(err) {
|
||||||
if err != nil {
|
err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644)
|
||||||
fmt.Println("Error creating config file")
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println("Error creating config file")
|
||||||
return
|
fmt.Println(err)
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HandleSignals()
|
HandleSignals()
|
||||||
LuaInit()
|
LuaInit()
|
||||||
|
@ -83,7 +85,7 @@ func main() {
|
||||||
|
|
||||||
//fmt.Printf(prompt)
|
//fmt.Printf(prompt)
|
||||||
|
|
||||||
cmdString, err := readline.String(prompt)
|
cmdString, err := readline.String(fmtPrompt())
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
break
|
break
|
||||||
|
@ -94,7 +96,10 @@ func main() {
|
||||||
cmdString = strings.TrimSuffix(cmdString, "\n")
|
cmdString = strings.TrimSuffix(cmdString, "\n")
|
||||||
err = l.DoString(cmdString)
|
err = l.DoString(cmdString)
|
||||||
|
|
||||||
if err == nil { continue }
|
if err == nil {
|
||||||
|
readline.AddHistory(cmdString)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
cmdArgs := splitInput(cmdString)
|
cmdArgs := splitInput(cmdString)
|
||||||
if len(cmdArgs) == 0 { continue }
|
if len(cmdArgs) == 0 { continue }
|
||||||
|
@ -129,12 +134,49 @@ func main() {
|
||||||
default:
|
default:
|
||||||
err := execCommand(cmdString)
|
err := execCommand(cmdString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
if syntax.IsIncomplete(err) {
|
||||||
|
sb := &strings.Builder{}
|
||||||
|
for {
|
||||||
|
done := StartMultiline(cmdString, sb)
|
||||||
|
if done {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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 {
|
func splitInput(input string) []string {
|
||||||
quoted := false
|
quoted := false
|
||||||
cmdArgs := []string{}
|
cmdArgs := []string{}
|
||||||
|
@ -165,10 +207,7 @@ func splitInput(input string) []string {
|
||||||
func execCommand(cmd string) error {
|
func execCommand(cmd string) error {
|
||||||
file, err := syntax.NewParser().Parse(strings.NewReader(cmd), "")
|
file, err := syntax.NewParser().Parse(strings.NewReader(cmd), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if syntax.IsIncomplete(err) {
|
return err
|
||||||
fmt.Println("incomplete input")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
runner, _ := interp.New(
|
runner, _ := interp.New(
|
||||||
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
|
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
|
||||||
|
|
Loading…
Reference in New Issue