From The Compiler, 6 Years ago, written in Bash.
Embed
  1. #!/bin/bash
  2.  
  3. bulletwidth=1
  4. idwidth=8
  5. datewidth=11
  6.  
  7. if ! git rev-parse --git-dir &>/dev/null; then
  8.     echo "This does not seem to be a git repository!" >&2
  9.     exit 1
  10. fi
  11.  
  12. if [[ $1 == --full ]]; then
  13.     echo '\documentclass[11pt,oneside,a4paper]{scrartcl}'
  14. #    echo '\usepackage[utf8]{inputenc}'
  15.     echo '\usepackage[T1]{fontenc}'
  16.     echo '\usepackage{cmbright}'
  17.     echo '\usepackage{longtable}'
  18.     echo '\begin{document}'
  19. fi
  20.  
  21. echo '\newlength\gittextlength'
  22. echo '\setlength\gittextlength{\linewidth}'
  23. echo '\addtolength\gittextlength{-'"$((bulletwidth + idwidth + datewidth))"'ex}'
  24. echo '\newenvironment{gitcommits}%'
  25. echo '    {\begin{longtable}{'"p{${bulletwidth}ex}p{${idwidth}ex}p{${datewidth}ex}"'p{\the\gittextlength}}}%'
  26. echo '    {\end{longtable}}'
  27. echo '\newcommand{\gitcommit}[3]{\textbullet & \textbf{#1} & \emph{#2} & #3 \\}'
  28. echo
  29. echo '\begin{gitcommits}'
  30.  
  31. { git log --date=short --format='format:%h %ad %s'; echo; } | while read -r id date msg; do
  32.     msg=$(sed -e 's/\\/\\textbackslash/g' \
  33.               -e 's/~/\\textasciitilde/g' \
  34.               -e 's/\^/\\textasciicircum/g' \
  35.               -e 's/[%$_#{}&]/\\&/g' \
  36.               -e 's/[^\]\\text\(asciitilde\|asciicircum\|backslash\)/&{}/g' \
  37.               <<< "$msg")
  38.     echo "    \\gitcommit{$id}{$date}{$msg}"
  39. done
  40.  
  41. echo '\end{gitcommits}'
  42.  
  43. [[ $1 == --full ]] && echo '\end{document}'