mirror of https://github.com/Hilbis/Hilbish
feat: add command line flags and set SHELL, make commands exit on ctrl c
parent
50ac5e5772
commit
52cf7e4799
10
go.mod
10
go.mod
|
@ -2,4 +2,12 @@ module hilbish
|
|||
|
||||
go 1.16
|
||||
|
||||
require github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
|
||||
require (
|
||||
github.com/Nerdmaster/terminal v0.12.1 // indirect
|
||||
github.com/akamensky/argparse v1.2.2 // indirect
|
||||
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e // indirect
|
||||
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807 // indirect
|
||||
github.com/gdamore/tcell v1.4.0 // indirect
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
|
||||
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d // indirect
|
||||
)
|
||||
|
|
21
go.sum
21
go.sum
|
@ -1,6 +1,27 @@
|
|||
github.com/Nerdmaster/terminal v0.12.1 h1:DGb3ya55nZdqdBMjWQHNF5mHYHS2eJgYLqmw3KnE1cQ=
|
||||
github.com/Nerdmaster/terminal v0.12.1/go.mod h1:Dg6++m3aF+P/l8RdYb/2N6zK3CqvUfzhBreUNEWuQ8M=
|
||||
github.com/akamensky/argparse v1.2.2 h1:P17T0ZjlUNJuWTPPJ2A5dM1wxarHgHqfYH+AZTo2xQA=
|
||||
github.com/akamensky/argparse v1.2.2/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
|
||||
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e h1:4G8AYOOwZdDWOiJR6D6JXaFmj5BDS7c5D5PyqsG/+Hg=
|
||||
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e/go.mod h1:fmqtV+Wqx0uFYLN1F4VhjZdtT56Dr8c3yA7nALFsw/Q=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807 h1:jdjd5e68T4R/j4PWxfZqcKY8KtT9oo8IPNVuV4bSXDQ=
|
||||
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807/go.mod h1:Xoiu5VdKMvbRgHuY7+z64lhu/7lvax/22nzASF6GrO8=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
|
||||
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg=
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
|
||||
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d h1:jbzgAvDZn8aEnytae+4ou0J0GwFZoHR0hOrTg4qH8GA=
|
||||
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
38
main.go
38
main.go
|
@ -1,20 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
_ "bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
_ "os/user"
|
||||
"syscall"
|
||||
"os/signal"
|
||||
"strings"
|
||||
|
||||
"github.com/akamensky/argparse"
|
||||
"github.com/bobappleyard/readline"
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
const version = "0.0.4"
|
||||
var l *lua.LState
|
||||
var prompt string
|
||||
|
||||
func main() {
|
||||
parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
|
||||
verflag := parser.Flag("v", "version", &argparse.Options{
|
||||
Required: false,
|
||||
Help: "color palette to use",
|
||||
})
|
||||
|
||||
err := parser.Parse(os.Args)
|
||||
if err != nil {
|
||||
fmt.Print(parser.Usage(err))
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if *verflag {
|
||||
fmt.Printf("Hilbish v%s\n", version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
os.Setenv("SHELL", os.Args[0])
|
||||
HandleSignals()
|
||||
LuaInit()
|
||||
|
||||
|
@ -23,11 +46,11 @@ func main() {
|
|||
//dir, _ := os.Getwd()
|
||||
//host, _ := os.Hostname()
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
//reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
fmt.Printf(prompt)
|
||||
//fmt.Printf(prompt)
|
||||
|
||||
cmdString, err := reader.ReadString('\n')
|
||||
cmdString, err := readline.String(prompt)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
@ -52,11 +75,16 @@ func main() {
|
|||
if err := cmd.Run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
readline.AddHistory(cmdString)
|
||||
}
|
||||
}
|
||||
|
||||
func HandleSignals() {
|
||||
signal.Ignore(os.Interrupt)
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
}()
|
||||
}
|
||||
|
||||
func LuaInit() {
|
||||
|
|
Loading…
Reference in New Issue