@@ -6,6 +6,7 @@ import (
66 "io"
77 "log/slog"
88 "os"
9+ "path/filepath"
910
1011 tea "github.com/charmbracelet/bubbletea/v2"
1112 "github.com/charmbracelet/crush/internal/app"
@@ -112,6 +113,10 @@ func setupApp(cmd *cobra.Command) (*app.App, error) {
112113 }
113114 cfg.Permissions.SkipRequests = yolo
114115
116+ if err := createDotCrushDir(cfg.Options.DataDirectory); err != nil {
117+ return nil, err
118+ }
119+
115120 // Connect to DB; this will also run migrations.
116121 conn, err := db.Connect(ctx, cfg.Options.DataDirectory)
117122 if err != nil {
@@ -160,3 +165,18 @@ func ResolveCwd(cmd *cobra.Command) (string, error) {
160165 }
161166 return cwd, nil
162167}
168+
169+func createDotCrushDir(dir string) error {
170+ if err := os.MkdirAll(dir, 0o700); err != nil {
171+ return fmt.Errorf("failed to create data directory: %q %w", dir, err)
172+ }
173+
174+ gitIgnorePath := filepath.Join(dir, ".gitignore")
175+ if _, err := os.Stat(gitIgnorePath); os.IsNotExist(err) {
176+ if err := os.WriteFile(gitIgnorePath, []byte("*\n"), 0o644); err != nil {
177+ return fmt.Errorf("failed to create .gitignore file: %q %w", gitIgnorePath, err)
178+ }
179+ }
180+
181+ return nil
182+}