diff --git a/hilbish.go b/hilbish.go index 471c6bc..2555c6b 100644 --- a/hilbish.go +++ b/hilbish.go @@ -35,14 +35,14 @@ func HilbishLoader(L *lua.LState) int { 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") - util.SetField(L, mod, "home", lua.LString(homedir), "Home directory of the user") + util.SetField(L, mod, "home", lua.LString(curuser.HomeDir), "Home directory of the user") util.SetField(L, mod, "dataDir", lua.LString(dataDir), "Directory for Hilbish's data files") util.SetField(L, mod, "interactive", lua.LBool(interactive), "If this is an interactive shell") util.SetField(L, mod, "login", lua.LBool(interactive), "Whether this is a login shell") xdg := L.NewTable() util.SetField(L, xdg, "config", lua.LString(confDir), "XDG config directory") - util.SetField(L, xdg, "data", lua.LString(getenv("XDG_DATA_HOME", homedir + "/.local/share")), "XDG data directory") + util.SetField(L, xdg, "data", lua.LString(getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share")), "XDG data directory") L.SetField(mod, "xdg", xdg) util.Document(L, xdg, "Variables for the XDG base directory spec.") diff --git a/lua.go b/lua.go index 64f1a4e..f166872 100644 --- a/lua.go +++ b/lua.go @@ -89,13 +89,13 @@ func RunConfig(confpath string) { } func RunLogin() { - if _, err := os.Stat(homedir + "/.hprofile.lua"); os.IsNotExist(err) { + if _, err := os.Stat(curuser.HomeDir + "/.hprofile.lua"); os.IsNotExist(err) { return } if !login { return } - err := l.DoFile(homedir + "/.hprofile.lua") + err := l.DoFile(curuser.HomeDir + "/.hprofile.lua") if err != nil { fmt.Fprintln(os.Stderr, err, "\nAn error has occured while loading your login config!n") diff --git a/main.go b/main.go index 65fa640..e442b94 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,6 @@ var ( aliases = map[string]string{} luaCompletions = map[string]*lua.LFunction{} - homedir string confDir string curuser *user.User @@ -38,9 +37,9 @@ var ( ) func main() { - homedir, _ = os.UserHomeDir() - confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config") curuser, _ = user.Current() + homedir := curuser.HomeDir + confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config") preloadPath = strings.Replace(preloadPath, "~", homedir, 1) sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1) diff --git a/rl.go b/rl.go index 883cba4..13fc1db 100644 --- a/rl.go +++ b/rl.go @@ -53,7 +53,7 @@ func NewLineReader(prompt string) *LineReader { fileCompletions := append(completions, readline.FilenameCompleter(query, ctx)...) // filter out executables for _, f := range fileCompletions { - name := strings.Replace(f, "~", homedir, 1) + name := strings.Replace(f, "~", curuser.HomeDir, 1) if info, err := os.Stat(name); err == nil && info.Mode().Perm() & 0100 == 0 { continue }