mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "1eed4cc7ee70deb3eda5026db43007d00fe61929" and "20870b9004b9cad0441db069c8c11897b7f65686" have entirely different histories.
1eed4cc7ee
...
20870b9004
|
@ -27,9 +27,6 @@ func splitQuote(str string) []string {
|
||||||
sb.WriteRune(r)
|
sb.WriteRune(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(str, " ") {
|
|
||||||
split = append(split, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
if sb.Len() > 0 {
|
if sb.Len() > 0 {
|
||||||
split = append(split, sb.String())
|
split = append(split, sb.String())
|
||||||
|
|
17
exec.go
17
exec.go
|
@ -101,7 +101,7 @@ func runInput(input string, priv bool) {
|
||||||
cmdFinish(0, input, priv)
|
cmdFinish(0, input, priv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
input, exitCode, cont, err = handleSh(cmdString)
|
input, exitCode, cont, err = handleSh(input)
|
||||||
case "hybridRev":
|
case "hybridRev":
|
||||||
_, _, _, err = handleSh(input)
|
_, _, _, err = handleSh(input)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -112,7 +112,7 @@ func runInput(input string, priv bool) {
|
||||||
case "lua":
|
case "lua":
|
||||||
input, exitCode, err = handleLua(cmdString)
|
input, exitCode, err = handleLua(cmdString)
|
||||||
case "sh":
|
case "sh":
|
||||||
input, exitCode, cont, err = handleSh(cmdString)
|
input, exitCode, cont, err = handleSh(input)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// can only be a string or function so
|
// can only be a string or function so
|
||||||
|
@ -152,7 +152,6 @@ func reprompt(input string) (string, error) {
|
||||||
for {
|
for {
|
||||||
in, err := continuePrompt(strings.TrimSuffix(input, "\\"))
|
in, err := continuePrompt(strings.TrimSuffix(input, "\\"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lr.SetPrompt(fmtPrompt(prompt))
|
|
||||||
return input, err
|
return input, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,17 +220,7 @@ func handleLua(cmdString string) (string, uint8, error) {
|
||||||
return cmdString, 125, err
|
return cmdString, 125, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSh(cmdString string) (input string, exitCode uint8, cont bool, runErr error) {
|
func handleSh(cmdString string) (string, uint8, bool, error) {
|
||||||
shRunner := hshMod.Get(rt.StringValue("runner")).AsTable().Get(rt.StringValue("sh"))
|
|
||||||
var err error
|
|
||||||
input, exitCode, cont, runErr, err = runLuaRunner(shRunner, cmdString)
|
|
||||||
if err != nil {
|
|
||||||
runErr = err
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func execSh(cmdString string) (string, uint8, bool, error) {
|
|
||||||
_, _, err := execCommand(cmdString, true)
|
_, _, err := execCommand(cmdString, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If input is incomplete, start multiline prompting
|
// If input is incomplete, start multiline prompting
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
local fs = require 'fs'
|
local fs = require 'fs'
|
||||||
|
|
||||||
local oldShRunner = hilbish.runner.sh
|
function cdHandle(inp)
|
||||||
function hilbish.runner.sh(input)
|
local res = hilbish.runner.lua(inp)
|
||||||
local res = oldShRunner(input)
|
|
||||||
|
if not res.err then
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
res = hilbish.runner.sh(inp)
|
||||||
|
|
||||||
if res.exit ~= 0 and hilbish.opts.autocd then
|
if res.exit ~= 0 and hilbish.opts.autocd then
|
||||||
local ok, stat = pcall(fs.stat, res.input)
|
local ok, stat = pcall(fs.stat, res.input)
|
||||||
|
@ -16,3 +21,5 @@ function hilbish.runner.sh(input)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hilbish.runner.setMode(cdHandle)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
ansi "github.com/acarl005/stripansi"
|
ansi "github.com/acarl005/stripansi"
|
||||||
|
"github.com/rivo/uniseg"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetPrompt will define the readline prompt string.
|
// SetPrompt will define the readline prompt string.
|
||||||
|
@ -208,7 +209,7 @@ func (rl *Instance) colorizeVimPrompt(p []rune) (cp []rune) {
|
||||||
// getting its real-printed length.
|
// getting its real-printed length.
|
||||||
func getRealLength(s string) (l int) {
|
func getRealLength(s string) (l int) {
|
||||||
stripped := ansi.Strip(s)
|
stripped := ansi.Strip(s)
|
||||||
return getWidth([]rune(stripped))
|
return uniseg.GraphemeClusterCount(stripped)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Instance) echoRightPrompt() {
|
func (rl *Instance) echoRightPrompt() {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
input, exitCode, cont, err := execSh(cmd)
|
input, exitCode, cont, err := handleSh(cmd)
|
||||||
var luaErr rt.Value = rt.NilValue
|
var luaErr rt.Value = rt.NilValue
|
||||||
if err != nil {
|
if err != nil {
|
||||||
luaErr = rt.StringValue(err.Error())
|
luaErr = rt.StringValue(err.Error())
|
||||||
|
|
Loading…
Reference in New Issue