Skip to content

Instantly share code, notes, and snippets.

@weakish
Created August 9, 2022 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weakish/eb086312b09407d4a2ae88cae06c9017 to your computer and use it in GitHub Desktop.
Save weakish/eb086312b09407d4a2ae88cae06c9017 to your computer and use it in GitHub Desktop.
generate dotfiles install scripts
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