diff --git a/main.go b/main.go index 411c3f0..d6ccbea 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( _ "github.com/daveberrys/guh/src/cmd/stash" _ "github.com/daveberrys/guh/src/cmd/undo" _ "github.com/daveberrys/guh/src/cmd/cli" + _ "github.com/daveberrys/guh/src/cmd/clone" ) func main() { cmd.Execute() } diff --git a/src/cmd/clone/root.go b/src/cmd/clone/root.go new file mode 100644 index 0000000..7af2331 --- /dev/null +++ b/src/cmd/clone/root.go @@ -0,0 +1,45 @@ +package clone + +import ( + "fmt" + "os" + "os/exec" + "strings" + + "github.com/daveberrys/guh/src/cmd" + "github.com/daveberrys/guh/src/utils" + "github.com/spf13/cobra" +) + +func init() { cmd.RootCmd.AddCommand(cloneCmd) } + +var cloneCmd = &cobra.Command{ + Use: "clone", + Short: "Clone a repository", + Args: cobra.MinimumNArgs(1), + RunE: func(cobraCmd *cobra.Command, args []string) error { + utils.RunGitSequence(false, []string{"clone", args[0]}) + + repoName := args[0] + if idx := strings.LastIndex(repoName, "/"); idx != -1 { + repoName = repoName[idx+1:] + } + repoName = strings.TrimSuffix(repoName, ".git") + + shell := os.Getenv("SHELL") + if shell == "" { shell = "sh" } + + fmt.Println("") + fmt.Printf("Spawning in a new shell: %s\n", shell) + fmt.Println("This will create a nested shell.") + + sh := exec.Command(shell) + sh.Dir = repoName + sh.Stdin = os.Stdin + sh.Stdout = os.Stdout + sh.Stderr = os.Stderr + sh.Run() + + return nil + }, +} \ No newline at end of file