mirror of https://github.com/Hilbis/Hilbish
Compare commits
3 Commits
32b421d402
...
8b5dc69950
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 8b5dc69950 | |
sammyette | 20a4cdb505 | |
TorchedSammy | 01d937afd8 |
10
api.go
10
api.go
|
@ -48,15 +48,15 @@ func hilbishLoader(L *lua.LState) int {
|
||||||
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!
|
|
||||||
Check out the {blue}{bold}guide{reset} command to get started.
|
|
||||||
`
|
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
greeting = `Welcome to {magenta}Hilbish{reset}, {cyan}` + username + `{reset}.
|
||||||
|
The nice lil shell for {blue}Lua{reset} fanatics!
|
||||||
|
Check out the {blue}{bold}guide{reset} command to get started.
|
||||||
|
`
|
||||||
|
|
||||||
util.SetField(L, mod, "ver", lua.LString(version), "Hilbish version")
|
util.SetField(L, mod, "ver", lua.LString(version), "Hilbish version")
|
||||||
util.SetField(L, mod, "user", lua.LString(username), "Username of user")
|
util.SetField(L, mod, "user", lua.LString(username), "Username of user")
|
||||||
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
||||||
|
|
25
exec.go
25
exec.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -17,6 +18,8 @@ import (
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var errNotExec = errors.New("not executable")
|
||||||
|
|
||||||
func runInput(input, origInput string) {
|
func runInput(input, origInput string) {
|
||||||
running = true
|
running = true
|
||||||
cmdString := aliases.Resolve(input)
|
cmdString := aliases.Resolve(input)
|
||||||
|
@ -137,8 +140,9 @@ func execCommand(cmd, old string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := lookpath(args[0])
|
err := lookpath(args[0])
|
||||||
if err == os.ErrPermission {
|
if err == errNotExec {
|
||||||
hooks.Em.Emit("command.no-perm", args[0])
|
hooks.Em.Emit("command.no-perm", args[0])
|
||||||
|
hooks.Em.Emit("command.not-executable", args[0])
|
||||||
return interp.NewExitStatus(126)
|
return interp.NewExitStatus(126)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
hooks.Em.Emit("command.not-found", args[0])
|
hooks.Em.Emit("command.not-found", args[0])
|
||||||
|
@ -156,19 +160,17 @@ func execCommand(cmd, old string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom lookpath function so we know if a command is found *and* has execute permission
|
func lookpath(file string) error { // custom lookpath function so we know if a command is found *and* is executable
|
||||||
func lookpath(file string) error {
|
|
||||||
skip := []string{"./", "/", "../", "~/"}
|
skip := []string{"./", "/", "../", "~/"}
|
||||||
for _, s := range skip {
|
for _, s := range skip {
|
||||||
if strings.HasPrefix(file, s) {
|
if strings.HasPrefix(file, s) {
|
||||||
err := findExecutable(file)
|
return findExecutable(file)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
||||||
path := filepath.Join(dir, file)
|
path := filepath.Join(dir, file)
|
||||||
err := findExecutable(path)
|
err := findExecutable(path)
|
||||||
if err == os.ErrPermission {
|
if err == errNotExec {
|
||||||
return err
|
return err
|
||||||
} else if err == nil {
|
} else if err == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -178,17 +180,6 @@ func lookpath(file string) error {
|
||||||
return os.ErrNotExist
|
return os.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
func findExecutable(name string) error {
|
|
||||||
f, err := os.Stat(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if m := f.Mode(); !m.IsDir() && m & 0111 != 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return os.ErrPermission
|
|
||||||
}
|
|
||||||
|
|
||||||
func splitInput(input string) ([]string, string) {
|
func splitInput(input string) ([]string, string) {
|
||||||
// end my suffering
|
// end my suffering
|
||||||
// TODO: refactor this garbage
|
// TODO: refactor this garbage
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
// +build linux darwin
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func findExecutable(path string) error {
|
||||||
|
f, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if m := f.Mode(); !m.IsDir() && m & 0111 != 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errNotExec
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func findExecutable(path string) error {
|
||||||
|
nameExt := filepath.Ext(path)
|
||||||
|
if nameExt == "" {
|
||||||
|
for _, ext := range filepath.SplitList(os.Getenv("PATHEXT")) {
|
||||||
|
_, err := os.Stat(path + ext)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err == nil {
|
||||||
|
return errNotExec
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.ErrNotExist
|
||||||
|
}
|
Loading…
Reference in New Issue