mirror of https://github.com/Hilbis/Hilbish
feat: add _user variable
this will probably change to a better global var in the future, but it's `_user` now. this provides a simple, guaranteed way of getting the current user's name $USER (in?)correctly shows the previous user when `su` is used, _user will always be root in this casepull/46/head
parent
60b1b50bb3
commit
a75100d15d
|
@ -9,7 +9,7 @@ function doPrompt(fail)
|
|||
end
|
||||
|
||||
print(ansikit.format('Welcome to {magenta}Hilbish{reset}, {cyan}' ..
|
||||
os.getenv 'USER' .. '{reset}.\n' ..
|
||||
_user .. '{reset}.\n' ..
|
||||
'The nice lil shell for {blue}Lua{reset} fanatics!\n'))
|
||||
|
||||
doPrompt()
|
||||
|
|
1
lua.go
1
lua.go
|
@ -23,6 +23,7 @@ func LuaInit() {
|
|||
l.OpenLibs()
|
||||
|
||||
l.SetGlobal("_ver", lua.LString(version))
|
||||
l.SetGlobal("_user", lua.LString(curuser.Username))
|
||||
|
||||
l.SetGlobal("prompt", l.NewFunction(hshprompt))
|
||||
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
|
||||
|
|
14
main.go
14
main.go
|
@ -4,9 +4,10 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"os/signal"
|
||||
"os/user"
|
||||
"strings"
|
||||
"path/filepath"
|
||||
|
||||
"hilbish/golibs/bait"
|
||||
|
||||
|
@ -27,15 +28,18 @@ var (
|
|||
commands = map[string]bool{}
|
||||
aliases = map[string]string{}
|
||||
|
||||
hooks bait.Bait
|
||||
homedir string
|
||||
curuser *user.User
|
||||
|
||||
running bool // Is a command currently running
|
||||
hooks bait.Bait
|
||||
interactive bool
|
||||
login bool // Are we the login shell?
|
||||
)
|
||||
|
||||
func main() {
|
||||
homedir, _ = os.UserHomeDir()
|
||||
curuser, _ = user.Current()
|
||||
defaultconfpath := homedir + "/.hilbishrc.lua"
|
||||
|
||||
// parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
|
||||
|
@ -169,16 +173,16 @@ func ContinuePrompt(prev string) (string, error) {
|
|||
|
||||
// This semi cursed function formats our prompt (obviously)
|
||||
func fmtPrompt() string {
|
||||
user, _ := user.Current()
|
||||
host, _ := os.Hostname()
|
||||
cwd, _ := os.Getwd()
|
||||
|
||||
cwd = strings.Replace(cwd, user.HomeDir, "~", 1)
|
||||
cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1)
|
||||
|
||||
args := []string{
|
||||
"d", cwd,
|
||||
"D", filepath.Base(cwd),
|
||||
"h", host,
|
||||
"u", user.Username,
|
||||
"u", curuser.Username,
|
||||
}
|
||||
|
||||
for i, v := range args {
|
||||
|
|
Loading…
Reference in New Issue