Created
August 9, 2022 01:16
-
-
Save weakish/eb086312b09407d4a2ae88cae06c9017 to your computer and use it in GitHub Desktop.
generate dotfiles install scripts
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"os" | |
"path/filepath" | |
) | |
// go run script/setup.go > script/setup | |
// ./script/setup | |
func main() { | |
fmt.Println("#!/bin/sh") | |
filepath.Walk(".", func(path string, info os.FileInfo, err error) error { | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "failed to access %q: %v\n", path, err) | |
return err | |
} | |
if info.IsDir() { | |
if info.Name() == ".git" || info.Name() == "script" { | |
return filepath.SkipDir | |
} | |
return nil | |
} | |
if info.Name() == "README.md" { | |
return nil | |
} | |
dest := "$HOME/" + path | |
fmt.Printf("mkdir -p `dirname %q`\n", dest) | |
fmt.Printf("install -p %q %q\n", path, dest) | |
return nil | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment