-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite setting up windows terminals scripts with golang
- Loading branch information
Showing
7 changed files
with
110 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//go:build windows | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
|
||
"github.com/kachick/dotfiles" | ||
) | ||
|
||
func main() { | ||
dotsPathFlag := flag.String("dotfiles_path", "", "Specify dotfiles repository path in your local") | ||
pwshProfilePathFlag := flag.String("pwsh_profile_path", "", "Specify PowerShell profile path") | ||
flag.Parse() | ||
dotsPath := filepath.Clean(*dotsPathFlag) | ||
pwshProfilePath := filepath.Clean(*pwshProfilePathFlag) | ||
|
||
if dotsPath == "" || pwshProfilePath == "" || len(os.Args) < 2 { | ||
flag.Usage() | ||
log.Fatalf("called with wrong arguments") | ||
} | ||
|
||
homePath, err := os.UserHomeDir() | ||
if err != nil { | ||
log.Fatalf("Failed to get home directory: %+v", err) | ||
} | ||
|
||
appdataPath, ok := os.LookupEnv("APPDATA") | ||
if !ok { | ||
log.Fatalln("ENV APPDATA is not found") | ||
} | ||
|
||
// As I understand it, unix like permission masks will work even in windows... | ||
err = os.MkdirAll(filepath.Join(homePath, ".config", "alacritty"), 0750) | ||
if err != nil { | ||
log.Fatalf("Failed to create dotfiles directory: %+v", err) | ||
} | ||
err = os.MkdirAll(path.Join(appdataPath, "alacritty"), 0750) | ||
if err != nil { | ||
log.Fatalf("Failed to create path that will have alacritty.yml: %+v", err) | ||
} | ||
|
||
copies := []dotfiles.Copy{ | ||
{Src: filepath.Join(dotsPath, "home", ".config", "starship.toml"), Dst: filepath.Join(homePath, ".config", "starship.toml")}, | ||
{Src: filepath.Join(dotsPath, "home", ".config", "alacritty", "alacritty-common.yml"), Dst: filepath.Join(homePath, ".config", "alacritty", "alacritty-common.yml")}, | ||
{Src: filepath.Join(dotsPath, "home", ".config", "alacritty", "alacritty-windows.yml"), Dst: filepath.Join(homePath, ".config", "alacritty", "alacritty.yml")}, | ||
{Src: filepath.Join(dotsPath, "windows", "config", "Profile.ps1"), Dst: pwshProfilePath}, | ||
} | ||
|
||
for _, copy := range copies { | ||
err := copy.Run() | ||
if err != nil { | ||
log.Fatalf("Failed to copy file: %+v %+v", copy, err) | ||
} | ||
} | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dotfiles | ||
|
||
import ( | ||
"io" | ||
"os" | ||
) | ||
|
||
type Copy struct { | ||
Src string | ||
Dst string | ||
} | ||
|
||
func (c Copy) Run() error { | ||
src, err := os.Open(c.Src) | ||
if err != nil { | ||
return err | ||
} | ||
defer src.Close() | ||
dst, err := os.Create(c.Dst) | ||
if err != nil { | ||
return err | ||
} | ||
defer dst.Close() | ||
|
||
_, err = io.Copy(dst, src) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.