Skip to content

Instantly share code, notes, and snippets.

@mzipay
Created July 27, 2016 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzipay/fe089c101038d37e92607adc1989ad3c to your computer and use it in GitHub Desktop.
Save mzipay/fe089c101038d37e92607adc1989ad3c to your computer and use it in GitHub Desktop.
Some BaSH functions I use for finding/viewing Python standard library modules easily
# show the location of a Python module's .py
# usage: pyfn module.name [pyversion]
# example: "pyfn hashlib", "pyfn hashlib 3.5", "pyfn hashlib 2"
function pyfn {
test -z "${1}" && return 1
fn=$(python${2} -c "import ${1},sys;sys.stdout.write(getattr(${1},'__file__').rsplit('.',1)[0]+'.py')")
test -f "${fn}" && echo "${fn}"
}
# open a Python module's .py in vi (read-only)
# usage: vipy module.name [pyversion]
# example: "vipy hashlib", "vipy hashlib 3.5", "vipy hashlib 2"
function vipy {
fn=$(pyfn ${1} ${2})
test -f "${fn}" && vi -R "${fn}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment