2
3
鏡像自 https://github.com/sammy-ette/Hilbish synced 2025-08-10 02:52:03 +00:00

比較提交

..

5 次程式碼提交

作者 SHA1 備註 日期
TorchedSammy
2e21af4d6b
refactor: use curuser to get homedir everywhere 2021-12-01 18:31:04 -04:00
TorchedSammy
effd028658
fix: substitution of home dir to ~ when names in path match it
fixes edge cases like `/mnt/home/user`
2021-12-01 18:30:03 -04:00
TorchedSammy
4a517bde5e
fix: remove handler when error in hook occurs 2021-12-01 17:35:12 -04:00
TorchedSammy
6a526dbbe4
fix: dont panic when error in bait hook occurs 2021-12-01 17:30:06 -04:00
TorchedSammy
3568b62219
style: use decl and assign operator instead of var and = 2021-12-01 17:29:14 -04:00
共有 6 個檔案被更改,包括 18 行新增11 行删除

查看文件

@ -1,6 +1,7 @@
package bait
import (
"fmt"
"hilbish/util"
"github.com/chuckpreslar/emission"
@ -13,8 +14,13 @@ type Bait struct{
}
func New() Bait {
emitter := emission.NewEmitter()
emitter.RecoverWith(func(hookname, hookfunc interface{}, err error) {
emitter.Off(hookname, hookfunc)
fmt.Println(err)
})
return Bait{
Em: emission.NewEmitter(),
Em: emitter,
}
}

查看文件

@ -18,7 +18,7 @@ func New() Commander {
}
func (c *Commander) Loader(L *lua.LState) int {
var exports = map[string]lua.LGFunction{
exports := map[string]lua.LGFunction{
"register": c.cregister,
"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, "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.")

4
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")

查看文件

@ -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)
@ -230,7 +229,9 @@ func fmtPrompt() string {
host, _ := os.Hostname()
cwd, _ := os.Getwd()
cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1)
if strings.HasPrefix(cwd, curuser.HomeDir) {
cwd = "~" + strings.TrimPrefix(cwd, curuser.HomeDir)
}
username := curuser.Username
// this will be baked into binary since GOOS is a constant
if runtime.GOOS == "windows" {

2
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
}