main dotfiles / bin / go-gen-std-tags
Eric Bower  ·  2026-09-08
 1#!/usr/bin/env bash
 2set -euo pipefail
 3
 4if ! command -v go >/dev/null 2>&1; then
 5  echo "error: go not found in PATH" >&2
 6  exit 1
 7fi
 8
 9if ! command -v ctags >/dev/null 2>&1; then
10  echo "error: ctags not found in PATH" >&2
11  exit 1
12fi
13
14goroot="$(go env GOROOT)"
15std_dir="${goroot}/src"
16
17if [[ -z "${goroot}" || ! -d "${std_dir}" ]]; then
18  echo "error: could not locate go std directory" >&2
19  exit 1
20fi
21
22cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/tags"
23target="${cache_dir}/go_std.tags"
24
25mkdir -p "${cache_dir}"
26
27echo "Generating Go standard library tags from ${std_dir}..."
28ctags --languages=Go --exclude=testdata -f "${target}" "${std_dir}"
29echo "Saved tags to ${target} ($(du -h "${target}" | cut -f1))"