mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	refactor!: use better default paths
~/.hilbishrc.lua has been removed and will no longer be loaded. instead, $XDG_CONFIG_HOME/hilbish/init.lua is to be used the history path has been changed to a more suited one. on linux, it is in $XDG_DATA_HOME/hilbish/.hilbish-history, or otherwise ~/.local/share/hilbish/.hilbish-history
This commit is contained in:
		
							parent
							
								
									cb3d0a2e8e
								
							
						
					
					
						commit
						f05ab921d7
					
				
							
								
								
									
										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)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								main.go
									
									
									
									
									
								
							@ -27,6 +27,7 @@ var (
 | 
			
		||||
	luaCompletions = map[string]*lua.LFunction{}
 | 
			
		||||
 | 
			
		||||
	confDir string
 | 
			
		||||
	userDataDir string
 | 
			
		||||
	curuser *user.User
 | 
			
		||||
 | 
			
		||||
	hooks bait.Bait
 | 
			
		||||
@ -40,25 +41,25 @@ func main() {
 | 
			
		||||
	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 {
 | 
			
		||||
		defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user