From 2cc78722741492285a7f4154abe5e0de179b1a95 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Tue, 14 Oct 2025 19:02:40 +0200 Subject: [PATCH] Add regedits --- install_context_menu.reg | 15 +++++++++++++++ main.go | 26 ++++++++++++++++++++++++++ uninstall_context_menu.reg | 5 +++++ 3 files changed, 46 insertions(+) create mode 100644 install_context_menu.reg create mode 100644 uninstall_context_menu.reg diff --git a/install_context_menu.reg b/install_context_menu.reg new file mode 100644 index 0000000..3cfc95e --- /dev/null +++ b/install_context_menu.reg @@ -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" diff --git a/main.go b/main.go index b072677..9e48fdd 100644 --- a/main.go +++ b/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 diff --git a/uninstall_context_menu.reg b/uninstall_context_menu.reg new file mode 100644 index 0000000..c3a278a --- /dev/null +++ b/uninstall_context_menu.reg @@ -0,0 +1,5 @@ +Windows Registry Editor Version 5.00 + +[-HKEY_CLASSES_ROOT\Directory\shell\AddToPath] + +[-HKEY_CLASSES_ROOT\Directory\Background\shell\AddToPath]