diff --git a/.gitignore b/.gitignore index c35431b..40e5c84 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # # Binaries for programs and plugins bender +dotctl *.exe *.exe~ *.dll diff --git a/Makefile b/Makefile index c03d245..432aa2d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ clean: - rm -rf test/bender_test 2> /dev/null + rm -rf test/dotctl_test 2> /dev/null rm -rf tmp 2> /dev/null sandbox: diff --git a/README.md b/README.md index 61abe57..f00e424 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ -# Bender -![](assets/bender.png) +# Dotctl A cli tool to manage your dotfiles ## About -Bender is a tool to help you easily manage your dotfiles and sync them across separate machines using +Dotctl is a tool to help you easily manage your dotfiles and sync them across separate machines using git. It aims to abstract away the manual effort of symlinking your dotfiles to config directories and updating them with git. @@ -14,11 +13,11 @@ updating them with git. ```bash # init sets up the config file and directory to hold all dotfiles -bender init --dotfile-path=/path/to/dotfile/repo -# add a config directory for bender to track -bender add /.config/nvim +dotctl init --dotfile-path=/path/to/dotfile/repo +# add a config directory for dotctl to track +dotctl add /.config/nvim # create symlinks -bender link +dotctl link ``` ## Development diff --git a/assets/bender.png b/assets/bender.png deleted file mode 100644 index bfec595..0000000 Binary files a/assets/bender.png and /dev/null differ diff --git a/cmd/add.go b/cmd/add.go index 7646376..cf2866b 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/Marcusk19/bender/tools" + "github.com/Marcusk19/dotctl/tools" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -17,7 +17,7 @@ func init() { var addCommand = &cobra.Command { Use: "add", - Short: "Adds config to be tracked by bender", + Short: "Adds config to be tracked by dotctl", Long: "TODO: add longer description", // TODO add more description Run: runAddCommand, } @@ -36,7 +36,7 @@ func runAddCommand(cmd *cobra.Command, args []string) { viper.Set(name, configSrc) err := viper.WriteConfig() if err != nil { - fmt.Printf("Problem updating bender config %s", err) + fmt.Printf("Problem updating dotctl config %s", err) } dotfilePath := viper.Get("dotfile-path").(string) diff --git a/cmd/backup.go b/cmd/backup.go deleted file mode 100644 index ccd5607..0000000 --- a/cmd/backup.go +++ /dev/null @@ -1,59 +0,0 @@ -package cmd - -import ( - "fmt" - "log" - "time" - - "github.com/Marcusk19/bender/tools" - "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing/object" - "github.com/spf13/cobra" -) - -func init() { - RootCmd.AddCommand(backupCommand) -} - -var backupCommand = &cobra.Command { - Use: "backup", - Short: "Add and commit files in dotfiles directory", - Run: runBackup, -} - - -func runBackup(cmd *cobra.Command, args []string) { - fmt.Fprintf(cmd.OutOrStdout(), "Backing up %s...\n", DotfilePath) - r, err := git.PlainOpen(DotfilePath) - if err != nil { - log.Fatal(err) - } - - worktree, err := r.Worktree() - if err != nil { - log.Fatal(err) - } - gitAddFiles(worktree, tools.AppFs) - - commitMessage := "backup " + time.Now().String() - - commit, err := worktree.Commit(commitMessage, &git.CommitOptions{ - Author: &object.Signature{ - Name: "bender CLI", - Email: "example@example.com", - When: time.Now(), - }, - }) - - if err != nil { - log.Fatal(err.Error()) - } - - obj, err := r.CommitObject(commit) - - if err != nil { - log.Fatal(err) - } - - fmt.Println(obj) -} diff --git a/cmd/init.go b/cmd/init.go index 025c12d..f90195f 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -7,7 +7,7 @@ import ( "path" "path/filepath" - "github.com/Marcusk19/bender/tools" + "github.com/Marcusk19/dotctl/tools" "github.com/go-git/go-git/v5" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -55,18 +55,18 @@ func runInitCommand(cmd *cobra.Command, args []string) { fs := FileSystem // if user has passed a dotfile path flag need to add it to // viper's search path for a config file - viper.AddConfigPath(filepath.Join(DotfilePath, "bender")) + viper.AddConfigPath(filepath.Join(DotfilePath, "dotctl")) if(viper.Get("testing") == true && fs.Name() != "MemMapFS") { log.Fatalf("wrong filesystem, got %s", fs.Name()) } - err := fs.MkdirAll(path.Join(DotfilePath, "bender"), 0755) + err := fs.MkdirAll(path.Join(DotfilePath, "dotctl"), 0755) if err != nil { log.Fatalf("Unable to create dotfile structure: %s", error.Error(err)) } - _, err = fs.Create(path.Join(DotfilePath, "bender/config")) + _, err = fs.Create(path.Join(DotfilePath, "dotctl/config")) if err != nil { panic(fmt.Errorf("Unable to create config file %w", err)) } diff --git a/cmd/link.go b/cmd/link.go index b233d78..3ac3a6b 100644 --- a/cmd/link.go +++ b/cmd/link.go @@ -13,6 +13,8 @@ import ( var linkCommand = &cobra.Command { Use: "link", Run: runLinkCommand, + Short: "generate symlinks according to config", + Long: "add longer description", // TODO add longer description here } func init() { @@ -29,7 +31,7 @@ func runLinkCommand(cmd *cobra.Command, args []string) { } for _, entry := range(entries) { configName := entry.Name() - if configName == ".git" || configName == "bender" { + if configName == ".git" || configName == "dotctl" { continue } dotPath := filepath.Join(dotfileRoot, entry.Name()) diff --git a/cmd/root.go b/cmd/root.go index 71dd675..98ae152 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,9 +15,9 @@ import ( var RootCmd = &cobra.Command{ - Use: "bender", + Use: "dotctl", Short: "dotfile management", - Long: `Bender is a CLI tool for syncing your + Long: `Dotctl is a CLI tool for syncing your dotfiles. It provides an opiniated way to symlink a dotfile directory to various config directories.`, } @@ -66,13 +66,13 @@ func init() { viper.SetConfigName("config") viper.SetConfigType("yaml") - viper.AddConfigPath("./tmp/dotfiles/bender") - viper.AddConfigPath(filepath.Join(DotfilePath, "bender")) + viper.AddConfigPath("./tmp/dotfiles/dotctl") + viper.AddConfigPath(filepath.Join(DotfilePath, "dotctl")) err := viper.ReadInConfig() if err != nil { - fmt.Println("No config detected. You can generate one by using 'bender init'") + fmt.Println("No config detected. You can generate one by using 'dotctl init'") } FileSystem = UseFilesystem() diff --git a/cmd/sync.go b/cmd/sync.go index 86e4e49..148f5df 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -28,7 +28,7 @@ func init() { "URL of remote repository", ) - viper.BindPFlag("bender-origin", syncCommand.Flags().Lookup("remote")) + viper.BindPFlag("dotctl-origin", syncCommand.Flags().Lookup("remote")) } var syncCommand = &cobra.Command{ @@ -62,7 +62,7 @@ func gitAddFiles(worktree *git.Worktree, fs afero.Fs) error { } func runSyncCommand(cmd *cobra.Command, args []string) { - origin := viper.GetString("bender-origin") + origin := viper.GetString("dotctl-origin") if origin == "" { fmt.Fprintln(cmd.OutOrStdout(), "No remote repository found") return @@ -126,7 +126,7 @@ func runSyncCommand(cmd *cobra.Command, args []string) { commit, err := w.Commit(commitMessage, &git.CommitOptions{ Author: &object.Signature{ - Name: "bender CLI", + Name: "dotctl CLI", Email: "example@example.com", When: time.Now(), }, diff --git a/go.mod b/go.mod index dfbc84f..960d32a 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/Marcusk19/bender +module github.com/Marcusk19/dotctl go 1.21.0 diff --git a/main.go b/main.go index 8848a15..aa36dcd 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ Copyright © 2024 NAME HERE */ package main -import "github.com/Marcusk19/bender/cmd" +import "github.com/Marcusk19/dotctl/cmd" func main() { cmd.Execute() diff --git a/test/copy_test.go b/test/copy_test.go index 083b1a6..4ae4f95 100644 --- a/test/copy_test.go +++ b/test/copy_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/Marcusk19/bender/tools" + "github.com/Marcusk19/dotctl/tools" "github.com/spf13/afero" ) diff --git a/test/init_test.go b/test/init_test.go index 736fe07..96f7fce 100644 --- a/test/init_test.go +++ b/test/init_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - "github.com/Marcusk19/bender/cmd" + "github.com/Marcusk19/dotctl/cmd" "github.com/spf13/afero" "github.com/spf13/viper" ) @@ -15,18 +15,18 @@ func TestInitCommand(t *testing.T) { fs := cmd.FileSystem - bender := cmd.RootCmd + dotctl := cmd.RootCmd actual := new(bytes.Buffer) - bender.SetOut(actual) - bender.SetErr(actual) - bender.SetArgs([]string{"init", "--dotfile-path=bender_test/dotfiles"}) + dotctl.SetOut(actual) + dotctl.SetErr(actual) + dotctl.SetArgs([]string{"init", "--dotfile-path=dotctl_test/dotfiles"}) - bender.Execute() + dotctl.Execute() - homedir := "bender_test/" + homedir := "dotctl_test/" - _, err := afero.ReadFile(fs, filepath.Join(homedir, "dotfiles/bender/config")) + _, err := afero.ReadFile(fs, filepath.Join(homedir, "dotfiles/dotctl/config")) if err != nil { t.Error(err.Error()) } diff --git a/test/link_test.go b/test/link_test.go index d04a5c9..0fea3ac 100644 --- a/test/link_test.go +++ b/test/link_test.go @@ -7,7 +7,7 @@ import ( "path/filepath" "testing" - "github.com/Marcusk19/bender/cmd" + "github.com/Marcusk19/dotctl/cmd" "github.com/spf13/viper" "github.com/stretchr/testify/assert" ) @@ -15,14 +15,14 @@ import ( func TestLinkCommand(t *testing.T) { setUpTesting() - bender := cmd.RootCmd + dotctl := cmd.RootCmd actual := new(bytes.Buffer) - bender.SetOut(actual) - bender.SetErr(actual) - bender.SetArgs([]string{"link"}) + dotctl.SetOut(actual) + dotctl.SetErr(actual) + dotctl.SetArgs([]string{"link"}) - bender.Execute() + dotctl.Execute() homedir := os.Getenv("HOME") someconfig := filepath.Join(homedir, ".config/someconfig/") @@ -38,8 +38,8 @@ func TestLinkCommand(t *testing.T) { func setUpTesting() { fs := cmd.FileSystem homedir := os.Getenv("HOME") - fs.MkdirAll(filepath.Join(homedir, ".dotfiles/bender"), 0755) - fs.Create(filepath.Join(homedir, ".dotfiles/bender/config")) + fs.MkdirAll(filepath.Join(homedir, ".dotfiles/dotctl"), 0755) + fs.Create(filepath.Join(homedir, ".dotfiles/dotctl/config")) fs.MkdirAll(filepath.Join(homedir, ".dotfiles/someconfig/"), 0755) viper.Set("dotfile-path", filepath.Join(homedir, ".dotfiles")) @@ -50,5 +50,5 @@ func setUpTesting() { func tearDownTesting() { fs := cmd.FileSystem - fs.RemoveAll("bender_test/") + fs.RemoveAll("dotctl_test/") } diff --git a/test/pretty_test.go b/test/pretty_test.go index 99604e2..e89c7bf 100644 --- a/test/pretty_test.go +++ b/test/pretty_test.go @@ -4,17 +4,17 @@ import ( "bytes" "testing" - "github.com/Marcusk19/bender/cmd" + "github.com/Marcusk19/dotctl/cmd" "github.com/stretchr/testify/assert" ) func TestPrettyCommand(t *testing.T) { - bender := cmd.RootCmd + dotctl := cmd.RootCmd actual := new(bytes.Buffer) - bender.SetOut(actual) - bender.SetErr(actual) - bender.SetArgs([]string{"pretty", "fixtures/test_pretty.txt"}) - bender.Execute() + dotctl.SetOut(actual) + dotctl.SetErr(actual) + dotctl.SetArgs([]string{"pretty", "fixtures/test_pretty.txt"}) + dotctl.Execute() expected := "The end of this sentence should start a newline. \nThe next sentence should be indented below this one.\n\tHello this is the end of the text" assert.Equal(t, expected, actual.String(), "actual value differs from expected")