Compare commits

..

No commits in common. "aeac0ccce02fbe053ebdd8418b95660ca088bfed" and "1ff3ff854b4397da4f876bfb802ebb52964a1456" have entirely different histories.

8 changed files with 16 additions and 109 deletions

View File

@ -4,13 +4,10 @@ BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/share/hilbish LIBDIR ?= $(PREFIX)/share/hilbish
build: build:
@go build -ldflags "-s -w" @go build
dev: build-dev:
@go build -ldflags "-s -w -X main.version=$(shell git describe --tags)" @go build -ldflags "-X main.version=$(git describe --tags)"
hilbiline:
@go build -ldflags "-s -w -X main.version=$(shell git describe --tags)+hilbiline" -tags hilbiline
install: install:
@install -v -d "$(DESTDIR)$(BINDIR)/" && install -m 0755 -v hilbish "$(DESTDIR)$(BINDIR)/hilbish" @install -v -d "$(DESTDIR)$(BINDIR)/" && install -m 0755 -v hilbish "$(DESTDIR)$(BINDIR)/hilbish"
@ -31,4 +28,4 @@ clean:
all: build install all: build install
.PHONY: install uninstall build dev hilbiline clean .PHONY: install uninstall build build-dev clean

View File

@ -51,25 +51,13 @@ sudo zypper install readline-devel
``` ```
### Install ### Install
First, clone Hilbish:
```sh ```sh
git clone --recursive https://github.com/Hilbis/Hilbish git clone --recursive https://github.com/Hilbis/Hilbish
cd Hilbish cd Hilbish
``` make build
Then build and install:
```sh
make dev
sudo make install sudo make install
# Or # Or
sudo make all sudo make all
```
Or, if you want the latest stable release:
```
git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
make build
sudo make install
``` ```
Alternatively, if you use Arch Linux, you can compile Hilbish with an **(unofficial)** AUR package: Alternatively, if you use Arch Linux, you can compile Hilbish with an **(unofficial)** AUR package:

1
go.mod
View File

@ -3,7 +3,6 @@ module hilbish
go 1.16 go 1.16
require ( require (
github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4 // indirect
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9
github.com/pborman/getopt v1.1.0 github.com/pborman/getopt v1.1.0

7
go.sum
View File

@ -1,5 +1,3 @@
github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4 h1:S9ulYwm5MUp02mEKnbDhVGjVBkdYV7/tmgEO1g3Q+Z8=
github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4/go.mod h1:mp9I7lvFoZ3ldAeydCzISakl6VdQYyrR8vVjmnKGqDo=
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e h1:4G8AYOOwZdDWOiJR6D6JXaFmj5BDS7c5D5PyqsG/+Hg= 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/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e/go.mod h1:fmqtV+Wqx0uFYLN1F4VhjZdtT56Dr8c3yA7nALFsw/Q=
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 h1:xz6Nv3zcwO2Lila35hcb0QloCQsc38Al13RNEzWRpX4= github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 h1:xz6Nv3zcwO2Lila35hcb0QloCQsc38Al13RNEzWRpX4=
@ -17,14 +15,10 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0= github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0=
github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk= github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk=
github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28= github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -39,7 +33,6 @@ golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4= golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20191110171634-ad39bd3f0407/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20191110171634-ad39bd3f0407/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=

18
main.go
View File

@ -12,6 +12,7 @@ import (
"hilbish/golibs/bait" "hilbish/golibs/bait"
"github.com/pborman/getopt" "github.com/pborman/getopt"
"github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"layeh.com/gopher-luar" "layeh.com/gopher-luar"
"golang.org/x/term" "golang.org/x/term"
@ -21,7 +22,6 @@ import (
var ( var (
version = "v0.4.0" version = "v0.4.0"
l *lua.LState l *lua.LState
lr *LineReader
prompt string // User's prompt, this will get set when lua side is initialized prompt string // User's prompt, this will get set when lua side is initialized
multilinePrompt = "> " multilinePrompt = "> "
@ -113,7 +113,8 @@ func main() {
RunLogin() RunLogin()
RunConfig(*configflag) RunConfig(*configflag)
lr = NewLineReader("") readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")
if *cmdflag != "" { if *cmdflag != "" {
RunInput(*cmdflag) RunInput(*cmdflag)
@ -132,8 +133,7 @@ func main() {
for interactive { for interactive {
running = false running = false
lr.SetPrompt(fmtPrompt()) input, err := readline.String(fmtPrompt())
input, err := lr.Read()
if err == io.EOF { if err == io.EOF {
// Exit if user presses ^D (ctrl + d) // Exit if user presses ^D (ctrl + d)
@ -171,8 +171,7 @@ func main() {
func ContinuePrompt(prev string) (string, error) { func ContinuePrompt(prev string) (string, error) {
hooks.Em.Emit("multiline", nil) hooks.Em.Emit("multiline", nil)
lr.SetPrompt(multilinePrompt) cont, err := readline.String(multilinePrompt)
cont, err := lr.Read()
if err != nil { if err != nil {
fmt.Println("") fmt.Println("")
return "", err return "", err
@ -215,14 +214,15 @@ func HandleSignals() {
for range c { for range c {
if !running { if !running {
//readline.ReplaceLine("", 0) readline.ReplaceLine("", 0)
//readline.RefreshLine() readline.RefreshLine()
} }
} }
} }
func HandleHistory(cmd string) { func HandleHistory(cmd string) {
lr.AddHistory(cmd) readline.AddHistory(cmd)
readline.SaveHistory(homedir + "/.hilbish-history")
// TODO: load history again (history shared between sessions like this ye) // TODO: load history again (history shared between sessions like this ye)
} }

36
rl.go
View File

@ -1,36 +0,0 @@
// +build !hilbiline
// Here we define a generic interface for readline and hilbiline,
// making them interchangable during build time
// this is normal readline
package main
import "github.com/bobappleyard/readline"
type LineReader struct {
Prompt string
}
// other gophers might hate this naming but this is local, shut up
func NewLineReader(prompt string) *LineReader {
readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")
return &LineReader{
Prompt: prompt,
}
}
func (lr *LineReader) Read() (string, error) {
return readline.String(lr.Prompt)
}
func (lr *LineReader) SetPrompt(prompt string) {
lr.Prompt = prompt
}
func (lr *LineReader) AddHistory(cmd string) {
readline.AddHistory(cmd)
readline.SaveHistory(homedir + "/.hilbish-history")
}

View File

@ -1,34 +0,0 @@
// +build hilbiline
// Here we define a generic interface for readline and hilbiline,
// making them interchangable during build time
// this is hilbiline's, as is obvious by the filename
package main
import "github.com/Hilbis/Hilbiline"
type LineReader struct {
hl *hilbiline.HilbilineState
}
// other gophers might hate this naming but this is local, shut up
func NewLineReader(prompt string) *LineReader {
hl := hilbiline.New(prompt)
return &LineReader{
&hl,
}
}
func (lr *LineReader) Read() (string, error) {
return lr.hl.Read()
}
func (lr *LineReader) SetPrompt(prompt string) {
lr.hl.SetPrompt(prompt)
}
func (lr *LineReader) AddHistory(cmd string) {
return
}

View File

@ -6,7 +6,7 @@ import (
"os" "os"
"strings" "strings"
// "github.com/bobappleyard/readline" "github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"github.com/yuin/gopher-lua/parse" "github.com/yuin/gopher-lua/parse"
"layeh.com/gopher-luar" "layeh.com/gopher-luar"
@ -132,7 +132,7 @@ func splitInput(input string) ([]string, string) {
cmdArgs := []string{} cmdArgs := []string{}
sb := &strings.Builder{} sb := &strings.Builder{}
cmdstr := &strings.Builder{} cmdstr := &strings.Builder{}
lastcmd := "" //readline.GetHistory(readline.HistorySize() - 1) lastcmd := readline.GetHistory(readline.HistorySize() - 1)
for _, r := range input { for _, r := range input {
if r == '"' { if r == '"' {