Skip to content

Commit

Permalink
Rewrite registry editing scripts in windows with golang
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Aug 22, 2023
1 parent a2a2850 commit 57c0e48
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"nil": {
"formatting": { "command": ["nixpkgs-fmt"] }
}
},
"gopls": {
"build.buildFlags": ["-tags=linux,windows,darwin"]
}
}
2 changes: 2 additions & 0 deletions cmd/add_nix_channels/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux || darwin

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/deps/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux || darwin

package main

import (
Expand Down
25 changes: 25 additions & 0 deletions cmd/disable_windows_beeps/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build windows

package main

import (
"log"

"golang.org/x/sys/windows/registry"
)

// # https://github.com/kachick/times_kachick/issues/214
func main() {
key, err := registry.OpenKey(registry.CURRENT_USER, `Control Panel\Sound`, registry.SET_VALUE)
if err != nil {
log.Fatalf("Failed to open registry key: %+v", err)
}
defer key.Close()

err = key.SetStringValue("Beep", "no")
if err != nil {
log.Fatalf("Failed to update registry: %+v", err)
}

log.Println("Completed to disable beeps, you need to restart Windows to activate settings")
}
2 changes: 2 additions & 0 deletions cmd/enable_nix_login_shells/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux || darwin

package main

import (
Expand Down
33 changes: 33 additions & 0 deletions cmd/enable_windows_verbose_context_menu/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build windows

package main

import (
"log"

"golang.org/x/sys/windows/registry"
)

func main() {
key, err := registry.OpenKey(registry.CURRENT_USER, `Software\Classes\CLSID`, registry.CREATE_SUB_KEY)
if err != nil {
log.Fatalf("Failed to open registry key: %+v", err)
}
defer key.Close()

newKey, isExists, err := registry.CreateKey(key, `{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32`, registry.CREATE_SUB_KEY)
if err != nil {
log.Fatalf("Failed to update registry: %+v", err)
}
if isExists {
log.Println("Skipped to create registry key, because it is already exists")
return
}

err = newKey.SetStringValue("", "")
if err != nil {
log.Fatalf("Failed to set empty default value, may need to fallback manually: %+v", err)
}

log.Println("Completed to enable classic style of context menu, you need to restart all explorer.exe processes to activate settings")
}
2 changes: 2 additions & 0 deletions cmd/fmt/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux || darwin

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/lint/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux || darwin

package main

import (
Expand Down
1 change: 0 additions & 1 deletion cmd/setup_wsl/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

package main

Expand Down
14 changes: 14 additions & 0 deletions windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
1. Exclude the `$PROFILE\Profile.ps1` from Anti Virus detection as Microsoft Defender
1. Enable Bitlocker and backup the restore key

## How to run go scripts in this repo?

After installed golang with winget

```console
Administrator in ~ psh
> go run github.com/kachick/dotfiles/cmd/disable_windows_beeps@0ed52e4341624d7216d0b97a9b9bbab3719a8377
2023/08/22 15:34:18 Completed to disable beeps, you need to restart Windows to activate settings
> go run github.com/kachick/dotfiles/cmd/disable_windows_beeps@0ed52e4341624d7216d0b97a9b9bbab3719a8377
2023/08/22 15:40:42 Skipped to create registry key, because it is already exists
```

Specifying with branch name with the @ref may use cache, then specify commit ref

## How to install WSL2?

winget does not support it, run as follows
Expand Down
3 changes: 0 additions & 3 deletions windows/scripts/disable_beeps.ps1

This file was deleted.

2 changes: 0 additions & 2 deletions windows/scripts/enable_verbose_context_menu.ps1

This file was deleted.

0 comments on commit 57c0e48

Please sign in to comment.