mirror of https://github.com/Hilbis/Hilbish
Compare commits
6 Commits
20870b9004
...
1eed4cc7ee
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 1eed4cc7ee | |
TorchedSammy | c13889592f | |
TorchedSammy | 2e192be2e1 | |
TorchedSammy | c96605e79c | |
TorchedSammy | a1ce2ecba6 | |
TorchedSammy | a1410ae7ad |
|
@ -27,6 +27,9 @@ 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(input)
|
input, exitCode, cont, err = handleSh(cmdString)
|
||||||
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(input)
|
input, exitCode, cont, err = handleSh(cmdString)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// can only be a string or function so
|
// can only be a string or function so
|
||||||
|
@ -152,6 +152,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +221,17 @@ func handleLua(cmdString string) (string, uint8, error) {
|
||||||
return cmdString, 125, err
|
return cmdString, 125, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSh(cmdString string) (string, uint8, bool, error) {
|
func handleSh(cmdString string) (input string, exitCode uint8, cont bool, runErr 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,13 +1,8 @@
|
||||||
local fs = require 'fs'
|
local fs = require 'fs'
|
||||||
|
|
||||||
function cdHandle(inp)
|
local oldShRunner = hilbish.runner.sh
|
||||||
local res = hilbish.runner.lua(inp)
|
function hilbish.runner.sh(input)
|
||||||
|
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)
|
||||||
|
@ -21,5 +16,3 @@ function cdHandle(inp)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
hilbish.runner.setMode(cdHandle)
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ 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.
|
||||||
|
@ -209,7 +208,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 uniseg.GraphemeClusterCount(stripped)
|
return getWidth([]rune(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 := handleSh(cmd)
|
input, exitCode, cont, err := execSh(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