cat <<EOF | tee "${PWD}"/.gitignore
# KiCad 9.0 - Files to ignore

# Backup files
*-backups/
*.kicad_pcb-bak
*.kicad_sch-bak
_autosave-*
*.tmp
*.tmp-bak
*.bck

# Cache and temporary files
fp-info-cache
sym-lib-cache
*.kicad_prl
*.kicad_wks
*.gbrjob
*.lck

# Exported production files (regenerable)
# Uncomment the lines below if you *want* to version these
# Gerbers/
# Drill/
# exported_gerbers/
# *.pdf
# *.csv  # BOM files

# Netlist exports
*.net
*.xml

# Reports
*.rpt
drc_result.rpt

# Plot files
*.plt

# Local symbol/footprint libraries if using global ones
# (If your libs are project-specific, comment these OUT)
# sym-lib-table
# fp-lib-table

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
EOF

cat <<EOF | tee "${PWD}"/.gitattributes
*.pro filter=kicad_project
*.sch filter=kicad_sch

# Treat KiCad files as text (for better diffing)
*.kicad_pcb text
*.kicad_sch text
*.kicad_sym text
*.kicad_mod text
*.kicad_wks text
*.net text
*.dsn text
*.pro text
*.kicad_pro text

EOF

# removing the date in the .pro file
git config --global filter.kicad_project.clean "sed -E 's/^update=.*$/update=Date/'"
git config --global filter.kicad_project.smudge cat

# Power and Flags Numbering
git config --global filter.kicad_sch.clean "sed -E 's/#(PWR|FLG)[0-9]+/#\1?/'"
git config --global filter.kicad_sch.smudge cat

## ~/.local/share/kicad/<version_numer>
# 3dmodels
# 3rdparty
# footprints
# kicad_advanced
# plugins
# projects
# scripting
# symbols
# template

mkdir -p -- symbols/ footprints/ 3dmodels/ manufacturing/ docs/

# git archive --format=zip --output=../myproject_v1.0.zip v1.0

#cat <<EOF > ${HOME}/bin/git-imgdiff
#!/bin/bash
#PIPE=$(mktemp -u)
#(! compare -metric RMSE $2 $1 png:${PIPE} 2> /dev/null) &&  (montage -geometry +4+4 $2 $PIPE $1 png:- | display -title "$1" -)
#rm $PIPE
#
#EOF
#
#chmod +x ${HOME}/bin/git-imgdiff

#see: http://github.com/jnavila/plotkicadsch
# https://jnavila.github.io/plotkicadsch/plotgitsch_usersguide.html
