Created
July 10, 2013 16:10
-
-
Save jphalip/5967635 to your computer and use it in GitHub Desktop.
Bash & zshell script for quickly accessing Python packages installed in the current virtualenv. Allows for tab completion.
Associated blog post: http://julienphalip.com/post/55092823910/a-script-to-quickly-access-the-source-of-installed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Julien Phalip | |
# License: BSD | |
# Description: Change the current directory to the path of the given Python package. | |
function goto { | |
cd `python -c "import pkgutil; print(pkgutil.get_loader('$1').filename)"` | |
} | |
function _top_level_packages { | |
python -c "import pkgutil; print('\n'.join([name for loader, name, ispkg in sorted(pkgutil.iter_modules()) if ispkg]))" | |
} | |
if [ -n "$BASH" ] ; then | |
_goto_complete () { | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
COMPREPLY=( $(compgen -W "`_top_level_packages`" -- ${cur}) ) | |
} | |
complete -o default -o nospace -F _goto_complete goto | |
elif [ -n "$ZSH_VERSION" ] ; then | |
_goto_complete () { | |
reply=( $(_top_level_packages) ) | |
} | |
compctl -K _goto_complete goto | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment