Add regedits

This commit is contained in:
2025-10-14 19:02:40 +02:00
parent 35766a6988
commit 2cc7872274
3 changed files with 46 additions and 0 deletions

26
main.go
View File

@@ -10,6 +10,7 @@ import (
)
func main() {
undo := flag.Bool("u", false, "Remove current directory from PATH")
flag.Parse()
logger.InitFlag()
@@ -45,6 +46,31 @@ func main() {
}
}
if *undo {
if !currentDirInPath {
logger.Info("Current directory is not in PATH")
return
}
// Remove current directory from PATH
var newDirs []string
for _, dir := range pathDirs {
if !strings.EqualFold(strings.TrimSpace(dir), currentDir) {
newDirs = append(newDirs, dir)
}
}
newPath := strings.Join(newDirs, ";")
err = key.SetStringValue("PATH", newPath)
if err != nil {
logger.Error("Failed to update PATH in registry: %v", err)
os.Exit(1)
}
logger.Info("Successfully removed current directory from PATH")
return
}
if currentDirInPath {
logger.Info("Current directory is already in PATH")
return