@@ -6,6 +6,7 @@ import (
10 tea "github.com/charmbracelet/bubbletea/v2"
11 tea "github.com/charmbracelet/bubbletea/v2"
11 "github.com/charmbracelet/crush/internal/app"
12 "github.com/charmbracelet/crush/internal/app"
@@ -112,6 +113,10 @@ func setupApp(cmd *cobra.Command) (*app.App, error) {
113 cfg.Permissions.SkipRequests = yolo
114 cfg.Permissions.SkipRequests = yolo
116+ if err := createDotCrushDir(cfg.Options.DataDirectory); err != nil {
115 // Connect to DB; this will also run migrations.
120 // Connect to DB; this will also run migrations.
116 conn, err := db.Connect(ctx, cfg.Options.DataDirectory)
121 conn, err := db.Connect(ctx, cfg.Options.DataDirectory)
117 if err != nil {
122 if err != nil {
@@ -160,3 +165,18 @@ func ResolveCwd(cmd *cobra.Command) (string, error) {
161 return cwd, nil
166 return cwd, nil
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)
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)