Compare commits

...

5 Commits

Author SHA1 Message Date
sammyette 5408e68e19
fix: use hilbish.cwd to get cwd 2021-05-27 19:06:45 -04:00
sammyette af4b4b2ae0
feat: add hilbish.cwd function 2021-05-27 19:06:17 -04:00
sammyette ba6d7972e0
chore: merge 2021-05-27 18:34:16 -04:00
Devin Singh 9573c2732d feat: cd - changes pwd to previous one
close #53
2021-05-27 17:26:02 -05:00
sammyette c1b9e5bc81
feat: add goro function
this function will run another function, but in a goroutine
!!
2021-05-25 20:44:03 -04:00
3 changed files with 24 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import (
var exports = map[string]lua.LGFunction { var exports = map[string]lua.LGFunction {
"run": run, "run": run,
"flag": flag, "flag": flag,
"cwd": cwd,
} }
func HilbishLoader(L *lua.LState) int { func HilbishLoader(L *lua.LState) int {
@ -53,3 +54,12 @@ func flag(L *lua.LState) int {
return 1 return 1
} }
func cwd(L *lua.LState) int {
cwd, _ := os.Getwd()
L.Push(lua.LString(cwd))
return 1
}

6
lua.go
View File

@ -12,6 +12,7 @@ import (
"hilbish/golibs/fs" "hilbish/golibs/fs"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"layeh.com/gopher-luar"
) )
var minimalconf = ` var minimalconf = `
@ -30,6 +31,7 @@ func LuaInit() {
l.SetGlobal("alias", l.NewFunction(hshalias)) l.SetGlobal("alias", l.NewFunction(hshalias))
l.SetGlobal("appendPath", l.NewFunction(hshappendPath)) l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
l.SetGlobal("exec", l.NewFunction(hshexec)) l.SetGlobal("exec", l.NewFunction(hshexec))
l.SetGlobal("goro", luar.New(l, hshgoroutine))
// yes this is stupid, i know // yes this is stupid, i know
l.PreloadModule("hilbish", HilbishLoader) l.PreloadModule("hilbish", HilbishLoader)
@ -151,3 +153,7 @@ func hshexec(L *lua.LState) int {
syscall.Exec(cmdPath, cmdArgs, os.Environ()) syscall.Exec(cmdPath, cmdArgs, os.Environ())
return 0 // random thought: does this ever return? return 0 // random thought: does this ever return?
} }
func hshgoroutine(gofunc func()) {
go gofunc()
}

View File

@ -3,6 +3,7 @@
local fs = require 'fs' local fs = require 'fs'
local commander = require 'commander' local commander = require 'commander'
local bait = require 'bait' local bait = require 'bait'
local old_dir = hilbish.cwd()
-- Builtins -- Builtins
commander.register('cd', function (args) commander.register('cd', function (args)
@ -13,7 +14,13 @@ commander.register('cd', function (args)
path = path .. tostring(args[i]) .. ' ' path = path .. tostring(args[i]) .. ' '
end end
path = path:gsub('$%$','\0'):gsub('${([%w_]+)}', os.getenv) path = path:gsub('$%$','\0'):gsub('${([%w_]+)}', os.getenv)
:gsub('$([%w_]+)', os.getenv):gsub('%z','$') :gsub('$([%w_]+)', os.getenv):gsub('%z','$'):gsub("%s+", "")
if path == '-' then
path = old_dir
print(path)
end
old_dir = hilbish.cwd()
local ok, err = pcall(function() fs.cd(path) end) local ok, err = pcall(function() fs.cd(path) end)
if not ok then if not ok then