Skip to content

Instantly share code, notes, and snippets.

@charles-l
Last active August 29, 2015 14:05
Show Gist options
  • Save charles-l/2db8acc81525bfb73d49 to your computer and use it in GitHub Desktop.
Save charles-l/2db8acc81525bfb73d49 to your computer and use it in GitHub Desktop.
Generates ctags for libraries included at the top of C/C++ files
# Generates ctags for libraries included at the top of C/C++ files
# Requires ctags.
echo "Looking for *.c, *.h, *.cpp, *.hpp"
files=()
for i in $(grep -sroh '#include [<|"].*["|>]' *.c *.h *.cpp *.hpp | sort | uniq)
do
if [[ $i != "#include" ]]
then
FILENAME=$(echo "${i:1:(${#i}-2)}")
if [[ $(echo ${i:0:1}) == '"' ]]
then
if [ -f ./$FILENAME ]
then
echo "Found $FILENAME in `pwd`"
files+=("./$FILENAME")
fi
else
if [ -f /usr/include/$FILENAME ]
then
echo "Found $FILENAME in /usr/include/"
files+=("/usr/include/$FILENAME")
fi
fi
fi
done
echo "Generating ctags..."
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ${files[*]}
echo "Done! Taglist created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment