Compare commits

...

2 Commits

Author SHA1 Message Date
307e494f68 Add mad ramblings 2024-10-02 22:50:30 +02:00
38b833582a Try cleaning up paths before adding them 2024-10-02 22:50:09 +02:00

35
main.go
View File

@@ -32,6 +32,11 @@ func init() {
log.Lmicroseconds|log.Lshortfile)
}
// I actually don't even know if this works or not.........
// Changes can be seen in windows system properties fucking thing
// But not in new terminals
// And rerunning the program even with a new terminal will result in the same output as the first run
// I really don't know whether or not this worked... And I don't know how to check
func main() {
currentPath := os.Getenv("PATH")
paths := strings.Split(currentPath, ";")
@@ -75,9 +80,35 @@ func main() {
}
for _, path := range alwaysInclude {
if !contains(cleanPaths, path) {
cleanPaths = append(cleanPaths, path)
path = filepath.Clean(path)
if !filepath.IsAbs(path) {
var err error
path, err = filepath.Abs(path)
if err != nil {
Error.Printf("error getting absolute path for %v: %v", path, err)
return
}
}
path = filepath.FromSlash(path)
fhandle, err := os.Open(path)
if err != nil {
if os.IsNotExist(err) {
Warning.Printf("Path %v does not exist", path)
continue
}
Warning.Printf("Error opening path %v: %v", path, err)
continue
}
fhandle.Close()
if slices.Contains(cleanPaths, path) {
Warning.Printf("Path %v already exists in cleanPaths", path)
continue
}
cleanPaths = append(cleanPaths, path)
log.Printf("Added path %v", path)
}
newPath := strings.Join(cleanPaths, ";")