My dotfiles. Period.

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. die() {
  3. echo "$@" >&2
  4. exit 2
  5. }
  6. mktmpl() {
  7. #
  8. # Make temporary template for git-commit and print its path
  9. #
  10. local mtmpl_name="$1"; shift
  11. local mtmpl_path
  12. local tmpl_path
  13. mtmpl_path="$HOME/.config/gittum/template/$mtmpl_name"
  14. test -f "$mtmpl_path" || die "no such meta-template: $mtmpl_path"
  15. bash -n "$mtmpl_path" || die
  16. tmpl_path="/.$(mktemp -t gittum-metacm.XXXXXXXX)"
  17. bash "$mtmpl_path" "$@" > "$tmpl_path" || die "template script exited with bad state: $?"
  18. printf %s "$tmpl_path"
  19. }
  20. main() {
  21. local name="$1"; shift
  22. local tmpl
  23. local interactive=true
  24. test -n "$1" && interactive=false
  25. tmpl="$(mktmpl "$name" "$@")"
  26. if $interactive;
  27. then
  28. git commit --verbose --template="$tmpl"
  29. else
  30. git commit -F "$tmpl"
  31. fi
  32. rm "$tmpl"
  33. }
  34. main "$@"