mirror of https://github.com/Hilbis/Hilbish
Compare commits
3 Commits
54689b7dd1
...
5787582c2e
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 5787582c2e | |
TorchedSammy | 9d685ab785 | |
TorchedSammy | bcbd4be7f9 |
|
@ -8,8 +8,7 @@ function doPrompt(fail)
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
print(lunacolors.format('Welcome to {magenta}Hilbish{reset}, {cyan}' .. hilbish.user
|
print(lunacolors.format(hilbish.greeting))
|
||||||
.. '{reset}.\n' .. 'The nice lil shell for {blue}Lua{reset} fanatics!\n'))
|
|
||||||
|
|
||||||
doPrompt()
|
doPrompt()
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,18 @@ var exports = map[string]lua.LGFunction {
|
||||||
"read": hlread,
|
"read": hlread,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var greeting string
|
||||||
|
|
||||||
func hilbishLoader(L *lua.LState) int {
|
func hilbishLoader(L *lua.LState) int {
|
||||||
mod := L.SetFuncs(L.NewTable(), exports)
|
mod := L.SetFuncs(L.NewTable(), exports)
|
||||||
|
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
username := curuser.Username
|
username := curuser.Username
|
||||||
|
|
||||||
|
greeting = `Welcome to {magenta}Hilbish{reset}, {cyan}` + curuser.Username + `{reset}.
|
||||||
|
The nice lil shell for {blue}Lua{reset} fanatics!
|
||||||
|
`
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
||||||
}
|
}
|
||||||
|
@ -39,6 +46,7 @@ func hilbishLoader(L *lua.LState) int {
|
||||||
util.SetField(L, mod, "dataDir", lua.LString(dataDir), "Directory for Hilbish's data files")
|
util.SetField(L, mod, "dataDir", lua.LString(dataDir), "Directory for Hilbish's data files")
|
||||||
util.SetField(L, mod, "interactive", lua.LBool(interactive), "If this is an interactive shell")
|
util.SetField(L, mod, "interactive", lua.LBool(interactive), "If this is an interactive shell")
|
||||||
util.SetField(L, mod, "login", lua.LBool(interactive), "Whether this is a login shell")
|
util.SetField(L, mod, "login", lua.LBool(interactive), "Whether this is a login shell")
|
||||||
|
util.SetField(L, mod, "greeting", lua.LString(greeting), "Hilbish's welcome message for interactive shells. It has Lunacolors formatting.")
|
||||||
util.Document(L, mod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
|
util.Document(L, mod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
|
||||||
|
|
||||||
// hilbish.userDir table
|
// hilbish.userDir table
|
||||||
|
|
20
lua.go
20
lua.go
|
@ -137,7 +137,23 @@ func hshalias(L *lua.LState) int {
|
||||||
// appendPath(dir)
|
// appendPath(dir)
|
||||||
// Appends `dir` to $PATH
|
// Appends `dir` to $PATH
|
||||||
func hshappendPath(L *lua.LState) int {
|
func hshappendPath(L *lua.LState) int {
|
||||||
dir := L.CheckString(1)
|
// check if dir is a table or a string
|
||||||
|
arg := L.Get(1)
|
||||||
|
fmt.Println(arg.Type())
|
||||||
|
if arg.Type() == lua.LTTable {
|
||||||
|
arg.(*lua.LTable).ForEach(func(k lua.LValue, v lua.LValue) {
|
||||||
|
appendPath(v.String())
|
||||||
|
})
|
||||||
|
} else if arg.Type() == lua.LTString {
|
||||||
|
appendPath(arg.String())
|
||||||
|
} else {
|
||||||
|
L.RaiseError("bad argument to appendPath (expected string or table, got %v)", L.Get(1).Type().String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendPath(dir string) {
|
||||||
dir = strings.Replace(dir, "~", curuser.HomeDir, 1)
|
dir = strings.Replace(dir, "~", curuser.HomeDir, 1)
|
||||||
pathenv := os.Getenv("PATH")
|
pathenv := os.Getenv("PATH")
|
||||||
|
|
||||||
|
@ -145,8 +161,6 @@ func hshappendPath(L *lua.LState) int {
|
||||||
if !strings.Contains(pathenv, dir) {
|
if !strings.Contains(pathenv, dir) {
|
||||||
os.Setenv("PATH", pathenv + string(os.PathListSeparator) + dir)
|
os.Setenv("PATH", pathenv + string(os.PathListSeparator) + dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// exec(cmd)
|
// exec(cmd)
|
||||||
|
|
16
shell.go
16
shell.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
|
"mvdan.cc/sh/v3/shell"
|
||||||
//"github.com/yuin/gopher-lua/parse"
|
//"github.com/yuin/gopher-lua/parse"
|
||||||
"mvdan.cc/sh/v3/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
|
@ -85,10 +86,19 @@ func execCommand(cmd string) error {
|
||||||
|
|
||||||
exechandle := func(ctx context.Context, args []string) error {
|
exechandle := func(ctx context.Context, args []string) error {
|
||||||
_, argstring := splitInput(strings.Join(args, " "))
|
_, argstring := splitInput(strings.Join(args, " "))
|
||||||
|
// i dont really like this but it works
|
||||||
|
if aliases.All()[args[0]] != "" {
|
||||||
|
for i, arg := range args {
|
||||||
|
if strings.Contains(arg, " ") {
|
||||||
|
args[i] = fmt.Sprintf("\"%s\"", arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, argstring = splitInput(strings.Join(args, " "))
|
||||||
|
|
||||||
// If alias was found, use command alias
|
// If alias was found, use command alias
|
||||||
argstring = aliases.Resolve(argstring)
|
argstring = aliases.Resolve(argstring)
|
||||||
args, _ = splitInput(argstring)
|
args, _ = shell.Fields(argstring, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// If command is defined in Lua then run it
|
// If command is defined in Lua then run it
|
||||||
luacmdArgs := l.NewTable()
|
luacmdArgs := l.NewTable()
|
||||||
|
|
Loading…
Reference in New Issue