#!/usr/bin/env bash
# inspired by https://tbaggery.com/2011/08/08/effortless-ctags-with-git.html
set -o errexit

main() {
  local git_dir
  git_dir="$(git rev-parse --git-dir)"

  local tmp_tags
  tmp_tags="$(mktemp)"

  trap 'rm -f "${tmp_tags}"' EXIT

  git ls-files |
    ctags \
      --tag-relative \
      -L - \
      -f"${tmp_tags}" \
      --languages=-javascript,sql

  mv "${tmp_tags}" "${git_dir}/tags"
}

main "${@}"
