Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gif.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
26 changes: 22 additions & 4 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ type contributor struct {
commits int
}

func getRepoInfo() repoInfo {
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 dir, err := os.Getwd(); err == nil {
parts := strings.Split(dir, string(os.PathSeparator))
info.name = parts[len(parts)-1]
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 {
Expand Down Expand Up @@ -116,6 +126,14 @@ func getRepoInfo() 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
}

Expand Down
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"
"os"

tea "github.com/charmbracelet/bubbletea"
Expand All @@ -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)
Expand All @@ -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] <directory>\n\n")
fmt.Println("Arguments:")
fmt.Println(" <directory> Directory to look for a git repository (if not supplied, defaults to current directory)")
fmt.Println()
fmt.Println("Options:")
fmt.Println(" --theme <name> Theme: default, matrix, spiderman")
fmt.Println(" --output <file> Export credits as GIF")
Expand All @@ -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
Expand All @@ -58,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)
}
Expand Down