In this example, fn is the binary we want to add tab completion to, and we
only attempt to complete after typing fn and then TAB. By checking
CURRENT == 2, we’re verifying the position of the cursor as the second field
in the command. This will complete with options foo, bar, and baz, and
filter the options accordingly as you start typing and hit TAB again.

Now that we understand how to configure tab completion for commands, next up is
determining how to extract useful information from the tags file. Here’s the
first few lines of the file from a project I worked on recently:

The tokens we want to use for tab completion are the first set of characters per
line, so we can use cut -f 1 path/to/tags to grab the first field. We then use
grep -v to ignore autogenerated ctags metadata we don’t care about. With a
bit of extra work (like writing stderr to /dev/null in the instance where
the tags file doesn’t exist yet), the end result looks like this: