12345678910111213141516171819202122 | #!/bin/bash
# blinker-tool
# description: Find where a name is defined in the project (functions,
# description: types, classes, constants, variables and so on), with its
# description: file, line and kind. Uses Universal Ctags, which knows most
# description: languages.
# arg name string: The name to look up, exactly as written in the code.
if ! ctags --version 2>/dev/null | grep -q 'Universal Ctags'; then
echo "Define needs Universal Ctags (https://ctags.io), which is not installed." >&2
exit 127
fi
# --options=NONE: the project cannot change how ctags runs.
out=$(ctags --quiet --options=NONE -R -x --sort=no \
--exclude=.git --exclude=node_modules \
--_xformat='%N %F:%n: %K %C' -f - . |
awk -F'\t' -v name="$1" '$1 == name { print $2 " " $3 }' | head -100)
if [ -z "$out" ]; then
echo "No definition of $1 found."
else
printf '%s\n' "$out"
fi
|