Created
March 20, 2015 15:35
-
-
Save john-g-g/5bf4fc56077d8c141789 to your computer and use it in GitHub Desktop.
Change directory to definition of specified python module
This file contains 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
# 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