fix: runtime errors on linux

this fixes out of bounds error since we tried to split the username
for '\' which is only valid on windows, so i added it for windows only
pull/69/head
sammyette 2021-09-25 21:39:06 -04:00
parent 7c815022a9
commit c95b0b55be
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
2 changed files with 12 additions and 2 deletions

View File

@ -5,6 +5,7 @@ package main
import ( import (
"os" "os"
"runtime"
"strings" "strings"
"github.com/pborman/getopt" "github.com/pborman/getopt"
@ -22,7 +23,11 @@ func HilbishLoader(L *lua.LState) int {
mod := L.SetFuncs(L.NewTable(), exports) mod := L.SetFuncs(L.NewTable(), exports)
host, _ := os.Hostname() host, _ := os.Hostname()
username := strings.Split(curuser.Username, "\\")[1] // for some reason Username includes the hostname on windows username := curuser.Username
// this will be baked into binary since GOOS is a constant
if runtime.GOOS == "windows" {
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
}
L.SetField(mod, "ver", lua.LString(version)) L.SetField(mod, "ver", lua.LString(version))
L.SetField(mod, "user", lua.LString(username)) L.SetField(mod, "user", lua.LString(username))

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"runtime"
"strings" "strings"
"os/signal" "os/signal"
"os/user" "os/user"
@ -265,7 +266,11 @@ func fmtPrompt() string {
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1) cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1)
username := strings.Split(curuser.Username, "\\")[1] // for some reason Username includes the hostname on windows username := curuser.Username
// this will be baked into binary since GOOS is a constant
if runtime.GOOS == "windows" {
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
}
args := []string{ args := []string{
"d", cwd, "d", cwd,