mirror of https://github.com/Hilbis/Hilbish
Compare commits
5 Commits
9defa737f4
...
5408e68e19
Author | SHA1 | Date |
---|---|---|
sammyette | 5408e68e19 | |
sammyette | af4b4b2ae0 | |
sammyette | ba6d7972e0 | |
Devin Singh | 9573c2732d | |
sammyette | c1b9e5bc81 |
10
hilbish.go
10
hilbish.go
|
@ -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
6
lua.go
|
@ -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()
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue