mirror of
https://github.com/Hilbis/Hilbish
synced 2025-05-12 15:23:23 +00:00
Compare commits
5 Commits
a9018a2740
...
23f6986123
Author | SHA1 | Date | |
---|---|---|---|
|
23f6986123 | ||
|
2d93f2ce4a | ||
|
b1f2a36639 | ||
|
204d50d73c | ||
|
0987899144 |
1
.github/semantic.yml
vendored
Normal file
1
.github/semantic.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
titleAndCommits: true
|
1
TODO.md
1
TODO.md
@ -7,3 +7,4 @@
|
|||||||
- [x] Hooks
|
- [x] Hooks
|
||||||
- [x] Aliases
|
- [x] Aliases
|
||||||
- [ ] hlua (hilbish lua) - 100% lua in the hilbish interactive shell, cuz why not
|
- [ ] hlua (hilbish lua) - 100% lua in the hilbish interactive shell, cuz why not
|
||||||
|
- [ ] Petals (name of plugins)
|
||||||
|
@ -2,6 +2,7 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
)
|
)
|
||||||
@ -26,7 +27,7 @@ var exports = map[string]lua.LGFunction{
|
|||||||
func cd(L *lua.LState) int {
|
func cd(L *lua.LState) int {
|
||||||
path := L.ToString(1)
|
path := L.ToString(1)
|
||||||
|
|
||||||
err := os.Chdir(path)
|
err := os.Chdir(strings.TrimSpace(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(*os.PathError).Err.Error() {
|
switch err.(*os.PathError).Err.Error() {
|
||||||
case "no such file or directory":
|
case "no such file or directory":
|
||||||
|
1
main.go
1
main.go
@ -108,6 +108,7 @@ func main() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
// If it succeeds, add to history and prompt again
|
// If it succeeds, add to history and prompt again
|
||||||
readline.AddHistory(cmdString)
|
readline.AddHistory(cmdString)
|
||||||
|
bait.Em.Emit("command.success", nil)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
preload.lua
18
preload.lua
@ -5,17 +5,23 @@ local fs = require 'fs'
|
|||||||
local commander = require 'commander'
|
local commander = require 'commander'
|
||||||
local bait = require 'bait'
|
local bait = require 'bait'
|
||||||
|
|
||||||
commander.register('cd', function (path)
|
commander.register('cd', function (args)
|
||||||
if #path == 1 then
|
bait.throw('cd', args)
|
||||||
local ok, err = pcall(function() fs.cd(path[1]) end)
|
if #args > 0 then
|
||||||
|
local path = ''
|
||||||
|
for i = 1, #args do
|
||||||
|
path = path .. tostring(args[i]) .. ' '
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok, err = pcall(function() fs.cd(path) end)
|
||||||
if not ok then
|
if not ok then
|
||||||
if err == 1 then
|
if err == 1 then
|
||||||
print('directory does not exist')
|
print('directory does not exist')
|
||||||
end
|
end
|
||||||
end
|
bait.throw('command.fail', nil)
|
||||||
bait.throw('cd', path)
|
else bait.throw('command.success', nil) end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
fs.cd(os.getenv 'HOME')
|
fs.cd(os.getenv 'HOME')
|
||||||
bait.throw('cd', path)
|
bait.throw('command.success', nil)
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user