From 568586ade2d43f94deeac654d34af08692f2046b Mon Sep 17 00:00:00 2001 From: Oakchris1955 Date: Sat, 28 Mar 2026 20:37:03 +0200 Subject: [PATCH 1/4] feat: argument for git repo directory --- git.go | 10 ++++++---- main.go | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/git.go b/git.go index 727ec28..011198c 100644 --- a/git.go +++ b/git.go @@ -25,12 +25,14 @@ type contributor struct { commits int } -func getRepoInfo() repoInfo { +func getRepoInfo(dir string) repoInfo { info := repoInfo{} - if dir, err := os.Getwd(); err == nil { - parts := strings.Split(dir, string(os.PathSeparator)) - info.name = parts[len(parts)-1] + if dir != "" { + if err := os.Chdir(dir); err != nil { + fmt.Fprintf(os.Stderr, "Error while attempting to navigate to directory \"%s\": %v\n", dir, err) + os.Exit(1) + } } if desc, err := os.ReadFile(".git/description"); err == nil { diff --git a/main.go b/main.go index 0d5154d..6ec7e3a 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "os" tea "github.com/charmbracelet/bubbletea" @@ -17,6 +18,7 @@ func main() { // parse flags theme := "default" output := "" + dir := "" for i, arg := range os.Args[1:] { if arg == "--version" || arg == "-v" { fmt.Printf("gitcredits %s (%s)\n", version, commit) @@ -25,7 +27,10 @@ func main() { if arg == "--help" || arg == "-h" { fmt.Println("gitcredits - Turn your Git repo into movie-style rolling credits") fmt.Println() - fmt.Printf("Usage: gitcredits [options]\n\n") + fmt.Printf("Usage: gitcredits [options] \n\n") + fmt.Println("Arguments:") + fmt.Println(" Directory to look for a git repository (if not supplied, defaults to current directory)") + fmt.Println() fmt.Println("Options:") fmt.Println(" --theme Theme: default, matrix, spiderman") fmt.Println(" --output Export credits as GIF") @@ -41,7 +46,13 @@ func main() { } } - info := getRepoInfo() + if len(os.Args) > 1 { + if !strings.HasPrefix("--", os.Args[len(os.Args)-2]) { + dir = os.Args[len(os.Args)-1] + } + } + + info := getRepoInfo(dir) width := 80 height := 24 From 0bec0e67a5a68536c6d958349ee605b21f1bc2db Mon Sep 17 00:00:00 2001 From: Oakchris1955 Date: Sun, 29 Mar 2026 15:23:56 +0300 Subject: [PATCH 2/4] fix: correctly handle argument --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 6ec7e3a..09826cf 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ func main() { } if len(os.Args) > 1 { - if !strings.HasPrefix("--", os.Args[len(os.Args)-2]) { + if !strings.HasPrefix(os.Args[len(os.Args)-2], "--") { dir = os.Args[len(os.Args)-1] } } From 543e8f49d3c3e4c04c56a405905ca161d5f8705c Mon Sep 17 00:00:00 2001 From: Oakchris1955 Date: Sun, 29 Mar 2026 15:48:51 +0300 Subject: [PATCH 3/4] chore: prevent possible directory disruptions after calling `getRepoInfo` function --- git.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/git.go b/git.go index 011198c..49e3a58 100644 --- a/git.go +++ b/git.go @@ -27,8 +27,16 @@ type contributor struct { func getRepoInfo(dir string) repoInfo { info := repoInfo{} + currentDir := "" if dir != "" { + if wd, err := os.Getwd(); err != nil { + fmt.Fprintf(os.Stderr, "Error while attempting check current working directory \"%s\": %v\n", dir, err) + os.Exit(1) + } else { + currentDir = wd + } + if err := os.Chdir(dir); err != nil { fmt.Fprintf(os.Stderr, "Error while attempting to navigate to directory \"%s\": %v\n", dir, err) os.Exit(1) @@ -118,6 +126,14 @@ func getRepoInfo(dir string) repoInfo { } } + // go back to the dirrectory we were when the function was invoked + if currentDir != "" { + if err := os.Chdir(currentDir); err != nil { + fmt.Fprintf(os.Stderr, "Error while attempting to navigate back to start directory \"%s\": %v\n", dir, err) + os.Exit(1) + } + } + return info } From 570cee1061d9ec39514a55db2263d99bc966b0f3 Mon Sep 17 00:00:00 2001 From: Oakchris1955 Date: Sun, 29 Mar 2026 15:49:21 +0300 Subject: [PATCH 4/4] fix: correctly generate credits with vhs for another repository --- gif.go | 7 ++++++- main.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gif.go b/gif.go index b47c843..eec97fe 100644 --- a/gif.go +++ b/gif.go @@ -8,7 +8,7 @@ import ( "strings" ) -func generateGIF(outputPath, theme string, lines []string, cardCount int) error { +func generateGIF(outputPath, theme string, dir string, lines []string, cardCount int) error { // check vhs installed vhsPath, err := exec.LookPath("vhs") if err != nil { @@ -62,9 +62,14 @@ func generateGIF(outputPath, theme string, lines []string, cardCount int) error tape.WriteString("Set TypingSpeed 0\n") cmd := selfPath + // perhaps we need some better logic here? if theme != "default" { cmd += " --theme " + theme } + if dir != "" { + cmd += " " + dir + } + tape.WriteString(fmt.Sprintf("Type \"%s\"\n", cmd)) tape.WriteString("Enter\n") tape.WriteString(fmt.Sprintf("Sleep %ds\n", duration)) diff --git a/main.go b/main.go index 09826cf..d24fe60 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,7 @@ func main() { default: cards = buildMatrixCards(info, 80, 24) } - if err := generateGIF(output, theme, credits, len(cards)); err != nil { + if err := generateGIF(output, theme, dir, credits, len(cards)); err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) }