Skip to content

Instantly share code, notes, and snippets.

@hamsolodev
Created May 31, 2013 05:44
Show Gist options
  • Select an option

  • Save hamsolodev/5683123 to your computer and use it in GitHub Desktop.

Select an option

Save hamsolodev/5683123 to your computer and use it in GitHub Desktop.
#!/bin/zsh -w
# This hook is run after this virtualenv is activated.
# If the virtualenv has a .project file in it then check to see the
# path contained within it exists, and if so collect etags for .py
# files in that path. Also includes etags generated for the
# virtualenv itself—if it finds them. Virtualenv tags are generated
# with the `venvtags` function defined in .zshrc: which should be run
# manually after, for example, installing new requirements. The
# resulting TAGS file is then hooked into the virtualenv by a
# .dir-locals.el file—which is created if it does not already
# exist—located at the project root.
PROJDIRFILE="${VIRTUAL_ENV}/${VIRTUALENVWRAPPER_PROJECT_FILENAME}"
if [ -f $PROJDIRFILE ] && [ -s $PROJDIRFILE ]
then
echo Running etags on project dir…
VENV_TAGS="${VIRTUAL_ENV}/TAGS"
if [ ! -z $VENV_TAGS ] && [ -f $VENV_TAGS ]
then
# venv tags already exist, so include them
ETAGS_VENV_INCLUDE="--include=$VENV_TAGS"
fi
find -L `cat $PROJDIRFILE` -type f -name "*.py" | xargs etags $ETAGS_VENV_INCLUDE -o `cat $PROJDIRFILE`/TAGS
# if the projectdir doesn't contain a .dir-locals.el file, create
# one to set tags-file-name variable to the TAGS file we just made
# (so that trying to visit a tag doesn't prompt for one).
if [ ! -f `cat $PROJDIRFILE`/.dir-locals.el ]
then
echo Setting up initial .dir-locals.el…
DIRLOCALS_EL="((nil . ((tags-file-name . \"`cat ${PROJDIRFILE}`/TAGS\" ))))"
echo $DIRLOCALS_EL > `cat $PROJDIRFILE`/.dir-locals.el
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment