Hallucinate an implementation

This commit is contained in:
2025-10-14 19:01:09 +02:00
parent faddcca0a8
commit 35766a6988
3 changed files with 62 additions and 5 deletions

57
main.go
View File

@@ -2,11 +2,66 @@ package main
import (
"flag"
"os"
"strings"
logger "git.site.quack-lab.dev/dave/cylogger"
"golang.org/x/sys/windows/registry"
)
func main() {
flag.Parse()
logger.InitFlag()
}
currentDir, err := os.Getwd()
if err != nil {
logger.Error("Failed to get current directory: %v", err)
os.Exit(1)
}
logger.Info("Current directory: %s", currentDir)
// Get current PATH from registry
key, err := registry.OpenKey(registry.CURRENT_USER, `Environment`, registry.QUERY_VALUE|registry.SET_VALUE)
if err != nil {
logger.Error("Failed to open registry key: %v", err)
os.Exit(1)
}
defer key.Close()
pathValue, _, err := key.GetStringValue("PATH")
if err != nil {
logger.Error("Failed to read PATH from registry: %v", err)
os.Exit(1)
}
// Check if current directory is already in PATH
pathDirs := strings.Split(pathValue, ";")
currentDirInPath := false
for _, dir := range pathDirs {
if strings.EqualFold(strings.TrimSpace(dir), currentDir) {
currentDirInPath = true
break
}
}
if currentDirInPath {
logger.Info("Current directory is already in PATH")
return
}
// Add current directory to PATH
newPath := pathValue
if newPath != "" && !strings.HasSuffix(newPath, ";") {
newPath += ";"
}
newPath += currentDir
err = key.SetStringValue("PATH", newPath)
if err != nil {
logger.Error("Failed to update PATH in registry: %v", err)
os.Exit(1)
}
logger.Info("Successfully added current directory to PATH")
}