mirror of https://github.com/Hilbis/Hilbish
Compare commits
6 Commits
4cc49d45c7
...
2a0cd1464a
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 2a0cd1464a | |
TorchedSammy | f05ab921d7 | |
TorchedSammy | cb3d0a2e8e | |
TorchedSammy | 209abfac77 | |
TorchedSammy | 5e9ea9fead | |
TorchedSammy | 11f193b394 |
|
@ -1,9 +1,9 @@
|
|||
-- Default Hilbish config
|
||||
lunacolors = require 'lunacolors'
|
||||
bait = require 'bait'
|
||||
local lunacolors = require 'lunacolors'
|
||||
local bait = require 'bait'
|
||||
|
||||
function doPrompt(fail)
|
||||
prompt(lunacolors.format(
|
||||
hilbish.prompt(lunacolors.format(
|
||||
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ '
|
||||
))
|
||||
end
|
||||
|
|
12
api.go
12
api.go
|
@ -7,7 +7,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
@ -63,17 +62,8 @@ The nice lil shell for {blue}Lua{reset} fanatics!
|
|||
|
||||
// hilbish.userDir table
|
||||
hshuser := L.NewTable()
|
||||
userConfigDir, _ := os.UserConfigDir()
|
||||
userDataDir := ""
|
||||
// i honestly dont know what directories to use for this
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
userDataDir = getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share")
|
||||
default:
|
||||
userDataDir = filepath.Join(userConfigDir)
|
||||
}
|
||||
|
||||
util.SetField(L, hshuser, "config", lua.LString(userConfigDir), "User's config directory")
|
||||
util.SetField(L, hshuser, "config", lua.LString(confDir), "User's config directory")
|
||||
util.SetField(L, hshuser, "data", lua.LString(userDataDir), "XDG data directory")
|
||||
util.Document(L, hshuser, "User directories to store configs and/or modules.")
|
||||
L.SetField(mod, "userDir", hshuser)
|
||||
|
|
55
main.go
55
main.go
|
@ -27,6 +27,7 @@ var (
|
|||
luaCompletions = map[string]*lua.LFunction{}
|
||||
|
||||
confDir string
|
||||
userDataDir string
|
||||
curuser *user.User
|
||||
|
||||
hooks bait.Bait
|
||||
|
@ -37,31 +38,30 @@ var (
|
|||
func main() {
|
||||
curuser, _ = user.Current()
|
||||
homedir := curuser.HomeDir
|
||||
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config")
|
||||
confDir, _ = os.UserConfigDir()
|
||||
preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
|
||||
sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1)
|
||||
|
||||
// i honestly dont know what directories to use for this
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
userDataDir = getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share")
|
||||
default:
|
||||
// this is fine on windows, dont know about others
|
||||
userDataDir = confDir
|
||||
}
|
||||
|
||||
if defaultConfDir == "" {
|
||||
// we'll add *our* default if its empty (wont be if its changed comptime)
|
||||
if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) {
|
||||
defaultConfPath = filepath.Join(homedir, "/.hilbishrc.lua")
|
||||
} else {
|
||||
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua")
|
||||
}
|
||||
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua")
|
||||
} else {
|
||||
// else do ~ substitution
|
||||
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
|
||||
}
|
||||
if defaultHistDir == "" {
|
||||
// we'll add *our* default if its empty (wont be if its changed comptime)
|
||||
if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) {
|
||||
defaultHistPath = filepath.Join(homedir, "/.hilbish-history")
|
||||
} else {
|
||||
defaultHistPath = filepath.Join(confDir, "hilbish", ".hilbish-history")
|
||||
}
|
||||
defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history")
|
||||
} else {
|
||||
// else do ~ substitution
|
||||
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbishrc.lua")
|
||||
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history")
|
||||
}
|
||||
helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags")
|
||||
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
|
||||
|
@ -113,35 +113,30 @@ func main() {
|
|||
os.Setenv("SHELL", os.Args[0])
|
||||
}
|
||||
|
||||
go handleSignals()
|
||||
luaInit()
|
||||
runLogin()
|
||||
// If user's config doesn't exixt,
|
||||
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
|
||||
// Read default from current directory
|
||||
// (this is assuming the current dir is Hilbish's git)
|
||||
input, err := os.ReadFile(".hilbishrc.lua")
|
||||
_, err := os.ReadFile(".hilbishrc.lua")
|
||||
confpath := ".hilbishrc.lua"
|
||||
if err != nil {
|
||||
// If it wasnt found, go to the real sample conf
|
||||
input, err = os.ReadFile(sampleConfPath)
|
||||
_, err = os.ReadFile(sampleConfPath)
|
||||
confpath = sampleConfPath
|
||||
if err != nil {
|
||||
fmt.Println("could not find .hilbishrc.lua or", sampleConfPath)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Create it using either default config we found
|
||||
err = os.WriteFile(defaultConfPath, input, 0644)
|
||||
if err != nil {
|
||||
// If that fails, bail
|
||||
fmt.Println("Error creating config file")
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
runConfig(confpath)
|
||||
} else {
|
||||
runConfig(*configflag)
|
||||
}
|
||||
|
||||
go handleSignals()
|
||||
luaInit()
|
||||
runLogin()
|
||||
runConfig(*configflag)
|
||||
|
||||
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
|
||||
scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
|
||||
for scanner.Scan() {
|
||||
|
|
|
@ -30,8 +30,10 @@ commander.register('cd', function (args)
|
|||
bait.throw('cd', path)
|
||||
|
||||
-- add to table of recent dirs
|
||||
table.insert(recentDirs, 1, path)
|
||||
recentDirs[11] = nil
|
||||
if recentDirs[#recentDirs - 1] ~= path then
|
||||
table.insert(recentDirs, 1, path)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue