Skip to content

Instantly share code, notes, and snippets.

@john-g-g
Created March 20, 2015 15:35
Show Gist options
  • Save john-g-g/5bf4fc56077d8c141789 to your computer and use it in GitHub Desktop.
Save john-g-g/5bf4fc56077d8c141789 to your computer and use it in GitHub Desktop.
Change directory to definition of specified python module
# Put it in your .bashrc or .bash_profile and do cdp <python module name>
# to get in the directory where the module is defined. This work:
# USAGE:
# ~ $ cdp os
# /usr/lib/python2.7 $
# ~ $ cdp os.path
# /usr/lib/python2.7 $
# It also works if a virtual environment is active.
cdp () {
cd "$(python -c "import os.path as _, ${1}; \
print(_.dirname(_.realpath(${1}.__file__[:-1])))"
)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment