Add regedits
This commit is contained in:
15
install_context_menu.reg
Normal file
15
install_context_menu.reg
Normal file
@@ -0,0 +1,15 @@
|
||||
Windows Registry Editor Version 5.00
|
||||
|
||||
[HKEY_CLASSES_ROOT\Directory\shell\AddToPath]
|
||||
@="Add to PATH"
|
||||
"Icon"="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"
|
||||
|
||||
[HKEY_CLASSES_ROOT\Directory\shell\AddToPath\command]
|
||||
@="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"
|
||||
|
||||
[HKEY_CLASSES_ROOT\Directory\Background\shell\AddToPath]
|
||||
@="Add to PATH"
|
||||
"Icon"="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"
|
||||
|
||||
[HKEY_CLASSES_ROOT\Directory\Background\shell\AddToPath\command]
|
||||
@="C:\\Users\\Administrator\\go\\bin\\windows-pathifier.exe"
|
||||
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
|
||||
|
||||
5
uninstall_context_menu.reg
Normal file
5
uninstall_context_menu.reg
Normal file
@@ -0,0 +1,5 @@
|
||||
Windows Registry Editor Version 5.00
|
||||
|
||||
[-HKEY_CLASSES_ROOT\Directory\shell\AddToPath]
|
||||
|
||||
[-HKEY_CLASSES_ROOT\Directory\Background\shell\AddToPath]
|
||||
Reference in New Issue
Block a user