Compare commits

..

No commits in common. "8b5dc6995017cd530cb64c0d80873c54a9ee5235" and "32b421d40294390d0b003ff70b14030ae6b2b449" have entirely different histories.

4 changed files with 22 additions and 58 deletions

10
api.go
View File

@ -48,15 +48,15 @@ func hilbishLoader(L *lua.LState) int {
host, _ := os.Hostname()
username := curuser.Username
if runtime.GOOS == "windows" {
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
}
greeting = `Welcome to {magenta}Hilbish{reset}, {cyan}` + username + `{reset}.
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" {
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
}
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, "host", lua.LString(host), "Host name of the machine")

25
exec.go
View File

@ -2,7 +2,6 @@ package main
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
@ -18,8 +17,6 @@ import (
"mvdan.cc/sh/v3/syntax"
)
var errNotExec = errors.New("not executable")
func runInput(input, origInput string) {
running = true
cmdString := aliases.Resolve(input)
@ -140,9 +137,8 @@ func execCommand(cmd, old string) error {
}
err := lookpath(args[0])
if err == errNotExec {
if err == os.ErrPermission {
hooks.Em.Emit("command.no-perm", args[0])
hooks.Em.Emit("command.not-executable", args[0])
return interp.NewExitStatus(126)
} else if err != nil {
hooks.Em.Emit("command.not-found", args[0])
@ -160,17 +156,19 @@ func execCommand(cmd, old string) error {
return err
}
func lookpath(file string) error { // custom lookpath function so we know if a command is found *and* is executable
// custom lookpath function so we know if a command is found *and* has execute permission
func lookpath(file string) error {
skip := []string{"./", "/", "../", "~/"}
for _, s := range skip {
if strings.HasPrefix(file, s) {
return findExecutable(file)
err := findExecutable(file)
return err
}
}
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
path := filepath.Join(dir, file)
err := findExecutable(path)
if err == errNotExec {
if err == os.ErrPermission {
return err
} else if err == nil {
return nil
@ -180,6 +178,17 @@ func lookpath(file string) error { // custom lookpath function so we know if a c
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) {
// end my suffering
// TODO: refactor this garbage

View File

@ -1,18 +0,0 @@
// +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
}

View File

@ -1,27 +0,0 @@
// +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
}