main dotfiles / bin / ts-gen-std-tags
Eric Bower  ·  2026-09-08
 1#!/usr/bin/env bash
 2set -euo pipefail
 3
 4if ! command -v ctags >/dev/null 2>&1; then
 5  echo "error: ctags not found in PATH" >&2
 6  exit 1
 7fi
 8
 9std_dir=""
10if command -v tsc >/dev/null 2>&1; then
11  tsc_real="$(realpath "$(command -v tsc)")"
12  ts_dir="$(dirname "$tsc_real")"
13  if [[ -d "${ts_dir}/../lib" ]]; then
14    std_dir="$(realpath "${ts_dir}/../lib")"
15  elif [[ -d "${ts_dir}/lib" ]]; then
16    std_dir="$(realpath "${ts_dir}/lib")"
17  fi
18fi
19
20if [[ -z "${std_dir}" || ! -d "${std_dir}" ]]; then
21  if command -v npm >/dev/null 2>&1; then
22    npm_root="$(npm root -g 2>/dev/null || true)"
23    if [[ -n "${npm_root}" && -d "${npm_root}/typescript/lib" ]]; then
24      std_dir="${npm_root}/typescript/lib"
25    fi
26  fi
27fi
28
29if [[ -z "${std_dir}" || ! -d "${std_dir}" ]]; then
30  echo "error: could not locate typescript lib directory" >&2
31  exit 1
32fi
33
34cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/tags"
35target="${cache_dir}/ts_std.tags"
36
37mkdir -p "${cache_dir}"
38
39echo "Generating TypeScript standard library tags from ${std_dir}..."
40ctags -f "${target}" "${std_dir}"/lib.*.d.ts
41echo "Saved tags to ${target} ($(du -h "${target}" | cut -f1))"