diff --git a/lua.go b/lua.go index 5e9ae55..49e20b9 100644 --- a/lua.go +++ b/lua.go @@ -80,6 +80,17 @@ func LuaInit(confpath string) { } } +func RunLogin() { + if _, err := os.Stat(homedir + "/.hprofile.lua"); os.IsNotExist(err) { + return + } + err = l.DoFile(homedir + "/.hprofile.lua") + if err != nil { + fmt.Fprintln(os.Stderr, err, + "\nAn error has occured while loading your login config!n") + } +} + func hshprompt(L *lua.LState) int { prompt = L.CheckString(1) diff --git a/main.go b/main.go index 4139e2b..7e74260 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,7 @@ const version = "0.4.0-dev.7" var ( l *lua.LState - // User's prompt, this will get set when lua side is initialized - prompt string + prompt string // User's prompt, this will get set when lua side is initialized multilinePrompt = "> " commands = map[string]bool{} @@ -30,8 +29,9 @@ var ( hooks bait.Bait homedir string - running bool + running bool // Is a command currently running interactive bool + login bool // Are we the login shell? ) func main() { @@ -49,6 +49,7 @@ func main() { _ = getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell") getopt.Parse() + loginshflag := getopt.Lookup('l').Seen() interactiveflag := getopt.Lookup('i').Seen() if *cmdflag == "" || interactiveflag { @@ -59,6 +60,11 @@ func main() { interactive = false } + // first arg, first character + if loginshflag || os.Args[0][0] == "-" { + login = true + } + if *verflag { fmt.Printf("Hilbish v%s\n", version) os.Exit(0) @@ -95,6 +101,7 @@ func main() { go HandleSignals() LuaInit(*configflag) + RunLogin() readline.Completer = readline.FilenameCompleter readline.LoadHistory(homedir + "/.hilbish-history")