Skip to content

Commit

Permalink
Merge a553be4 into f8f5d07
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick authored Mar 7, 2024
2 parents f8f5d07 + a553be4 commit 956b773
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 16 deletions.
70 changes: 57 additions & 13 deletions cmd/winit-conf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"embed"
"flag"
"fmt"
"log"
"os"
"path"
Expand Down Expand Up @@ -103,28 +104,71 @@ func (p provisioner) Copy() error {
return nil
}

func usage() string {
return `Usage: winit-conf [SUB] [OPTIONS]
Windows initialization to apply my settings for some apps
$ winit-conf.exe list
$ winit-conf.exe generate
$ winit-conf.exe run -pwsh_profile_path "$PROFILE"
`
}

func main() {
pwshProfilePathFlag := flag.String("pwsh_profile_path", "", "Specify PowerShell profile path")
runCmd := flag.NewFlagSet("run", flag.ExitOnError)
pwshProfilePathFlag := runCmd.String("pwsh_profile_path", "", "Specify PowerShell profile path")
flag.Usage = func() {
// https://github.com/golang/go/issues/57059#issuecomment-1336036866
fmt.Printf("%s", usage()+"\n\n")
flag.PrintDefaults()
}
flag.Parse()
// $PROFILE is an "Automatic Variables", not ENV
// https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4
pwshProfilePath := filepath.Clean(*pwshProfilePathFlag)

if pwshProfilePath == "" {
if len(os.Args) < 1 {
flag.Usage()
log.Fatalf("called with wrong arguments")

os.Exit(1)
}

for _, p := range provisioners(pwshProfilePath) {
log.Printf("%s => %s\n", p.EmbedPath(), p.DstPath())
err := p.Copy()
if err != nil {
log.Fatalf("Failed to copy file: %+v %+v", p, err)
switch os.Args[1] {
case "list":
for _, p := range provisioners("dummy_path") {
fmt.Println(p.EmbedPath())
}
case "generate":
for _, p := range provisioners("dummy_path") {
body, err := config.WindowsAssets.ReadFile(p.EmbedPath())
if err != nil {
fmt.Println(p.EmbedPath())
fmt.Println("--------------------------------------------------")
fmt.Println(string(body))
}
}
case "run":
if *pwshProfilePathFlag == "" {
flag.Usage()
log.Fatalf("called with wrong arguments")
}
// $PROFILE is an "Automatic Variables", not ENV
// https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4
pwshProfilePath := filepath.Clean(*pwshProfilePathFlag)

for _, p := range provisioners(pwshProfilePath) {
log.Printf("%s => %s\n", p.EmbedPath(), p.DstPath())
err := p.Copy()
if err != nil {
log.Fatalf("Failed to copy file: %+v %+v", p, err)
}
}
}

log.Printf(`Completed, you need to restart terminals
log.Printf(`Completed, you need to restart terminals
If you faced slow execution of PowerShell after this script, exclude %s from Anti Virus as Microsoft Defender
`, pwshProfilePath)
default:
flag.Usage()

os.Exit(1)
}
}
20 changes: 17 additions & 3 deletions cmd/winit-reg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func usage() string {
Windows initialization to modify default settings
$ winit-reg list
$ winit-reg run --action disable_beeps
$ winit-reg run --all
$ winit-reg.exe list
$ winit-reg.exe run --action disable_beeps
$ winit-reg.exe run --all
`
}

Expand All @@ -42,6 +42,20 @@ func main() {
actionFlag := runCmd.String("action", "", "which action you want to do")
allFlag := runCmd.Bool("all", false, "do ALL if you trust me")

flag.Usage = func() {
// https://github.com/golang/go/issues/57059#issuecomment-1336036866
fmt.Printf("%s", usage()+"\n\n")
flag.PrintDefaults()
}

flag.Parse()

if len(os.Args) < 1 {
flag.Usage()

os.Exit(1)
}

switch os.Args[1] {
case "list":
// TODO: prints current settings
Expand Down

0 comments on commit 956b773

Please sign in to comment.