mirror of https://github.com/Marcusk19/dotctl
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
910 B
Go
45 lines
910 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/afero"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(linkCommand)
|
|
}
|
|
|
|
var linkCommand = &cobra.Command {
|
|
Use: "link",
|
|
Run: runLinkCommand,
|
|
}
|
|
|
|
func runLinkCommand(cmd *cobra.Command, args []string) {
|
|
fs := UseFilesystem()
|
|
fmt.Println("Symlinking dotfiles...")
|
|
entries, err := afero.ReadDir(fs, DotfilePath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
for _, entry := range(entries) {
|
|
if entry.Name() == ".git" {
|
|
continue
|
|
}
|
|
dotPath := filepath.Join(DotfilePath, entry.Name())
|
|
configPath := filepath.Join(ConfigPath, entry.Name())
|
|
|
|
// destination needs to be removed before symlink
|
|
fs.RemoveAll(configPath)
|
|
|
|
err = afero.OsFs.SymlinkIfPossible(afero.OsFs{}, dotPath, configPath)
|
|
if err != nil {
|
|
log.Fatalf("Cannot symlink %s: %s", entry.Name(), err.Error())
|
|
}
|
|
}
|
|
|
|
}
|