Add regedits
This commit is contained in:
26
main.go
26
main.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user