mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "2e21af4d6bf3740ffac86cefe1200bb7cab9f154" and "34778a4bdffad3b1330a1c146833e381efd49313" have entirely different histories.
2e21af4d6b
...
34778a4bdf
|
@ -1,7 +1,6 @@
|
||||||
package bait
|
package bait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"hilbish/util"
|
"hilbish/util"
|
||||||
|
|
||||||
"github.com/chuckpreslar/emission"
|
"github.com/chuckpreslar/emission"
|
||||||
|
@ -14,13 +13,8 @@ type Bait struct{
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() Bait {
|
func New() Bait {
|
||||||
emitter := emission.NewEmitter()
|
|
||||||
emitter.RecoverWith(func(hookname, hookfunc interface{}, err error) {
|
|
||||||
emitter.Off(hookname, hookfunc)
|
|
||||||
fmt.Println(err)
|
|
||||||
})
|
|
||||||
return Bait{
|
return Bait{
|
||||||
Em: emitter,
|
Em: emission.NewEmitter(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ func New() Commander {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commander) Loader(L *lua.LState) int {
|
func (c *Commander) Loader(L *lua.LState) int {
|
||||||
exports := map[string]lua.LGFunction{
|
var exports = map[string]lua.LGFunction{
|
||||||
"register": c.cregister,
|
"register": c.cregister,
|
||||||
"deregister": c.cderegister,
|
"deregister": c.cderegister,
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,14 +35,14 @@ func HilbishLoader(L *lua.LState) int {
|
||||||
util.SetField(L, mod, "ver", lua.LString(version), "Hilbish version")
|
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, "user", lua.LString(username), "Username of user")
|
||||||
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
||||||
util.SetField(L, mod, "home", lua.LString(curuser.HomeDir), "Home directory of the user")
|
util.SetField(L, mod, "home", lua.LString(homedir), "Home directory of the user")
|
||||||
util.SetField(L, mod, "dataDir", lua.LString(dataDir), "Directory for Hilbish's data files")
|
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, "interactive", lua.LBool(interactive), "If this is an interactive shell")
|
||||||
util.SetField(L, mod, "login", lua.LBool(interactive), "Whether this is a login shell")
|
util.SetField(L, mod, "login", lua.LBool(interactive), "Whether this is a login shell")
|
||||||
|
|
||||||
xdg := L.NewTable()
|
xdg := L.NewTable()
|
||||||
util.SetField(L, xdg, "config", lua.LString(confDir), "XDG config directory")
|
util.SetField(L, xdg, "config", lua.LString(confDir), "XDG config directory")
|
||||||
util.SetField(L, xdg, "data", lua.LString(getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share")), "XDG data directory")
|
util.SetField(L, xdg, "data", lua.LString(getenv("XDG_DATA_HOME", homedir + "/.local/share")), "XDG data directory")
|
||||||
L.SetField(mod, "xdg", xdg)
|
L.SetField(mod, "xdg", xdg)
|
||||||
|
|
||||||
util.Document(L, xdg, "Variables for the XDG base directory spec.")
|
util.Document(L, xdg, "Variables for the XDG base directory spec.")
|
||||||
|
|
4
lua.go
4
lua.go
|
@ -89,13 +89,13 @@ func RunConfig(confpath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunLogin() {
|
func RunLogin() {
|
||||||
if _, err := os.Stat(curuser.HomeDir + "/.hprofile.lua"); os.IsNotExist(err) {
|
if _, err := os.Stat(homedir + "/.hprofile.lua"); os.IsNotExist(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !login {
|
if !login {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := l.DoFile(curuser.HomeDir + "/.hprofile.lua")
|
err := l.DoFile(homedir + "/.hprofile.lua")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err,
|
fmt.Fprintln(os.Stderr, err,
|
||||||
"\nAn error has occured while loading your login config!n")
|
"\nAn error has occured while loading your login config!n")
|
||||||
|
|
9
main.go
9
main.go
|
@ -28,6 +28,7 @@ var (
|
||||||
aliases = map[string]string{}
|
aliases = map[string]string{}
|
||||||
luaCompletions = map[string]*lua.LFunction{}
|
luaCompletions = map[string]*lua.LFunction{}
|
||||||
|
|
||||||
|
homedir string
|
||||||
confDir string
|
confDir string
|
||||||
curuser *user.User
|
curuser *user.User
|
||||||
|
|
||||||
|
@ -37,9 +38,9 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
curuser, _ = user.Current()
|
homedir, _ = os.UserHomeDir()
|
||||||
homedir := curuser.HomeDir
|
|
||||||
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config")
|
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config")
|
||||||
|
curuser, _ = user.Current()
|
||||||
preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
|
preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
|
||||||
sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1)
|
sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1)
|
||||||
|
|
||||||
|
@ -229,9 +230,7 @@ func fmtPrompt() string {
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
if strings.HasPrefix(cwd, curuser.HomeDir) {
|
cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1)
|
||||||
cwd = "~" + strings.TrimPrefix(cwd, curuser.HomeDir)
|
|
||||||
}
|
|
||||||
username := curuser.Username
|
username := curuser.Username
|
||||||
// this will be baked into binary since GOOS is a constant
|
// this will be baked into binary since GOOS is a constant
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
|
|
2
rl.go
2
rl.go
|
@ -53,7 +53,7 @@ func NewLineReader(prompt string) *LineReader {
|
||||||
fileCompletions := append(completions, readline.FilenameCompleter(query, ctx)...)
|
fileCompletions := append(completions, readline.FilenameCompleter(query, ctx)...)
|
||||||
// filter out executables
|
// filter out executables
|
||||||
for _, f := range fileCompletions {
|
for _, f := range fileCompletions {
|
||||||
name := strings.Replace(f, "~", curuser.HomeDir, 1)
|
name := strings.Replace(f, "~", homedir, 1)
|
||||||
if info, err := os.Stat(name); err == nil && info.Mode().Perm() & 0100 == 0 {
|
if info, err := os.Stat(name); err == nil && info.Mode().Perm() & 0100 == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue