From: Travis Swicegood Date: Wed, 26 Mar 2014 14:58:24 +0000 (-0500) Subject: Add a pyedit command thanks to @srossross X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=ee793d4cce81ef65faa7aa1e75a68a5d35b46eb8;p=common%2Fbash_it.git Add a pyedit command thanks to @srossross --- diff --git a/plugins/available/python.plugin.bash b/plugins/available/python.plugin.bash index c705d5b..5197078 100644 --- a/plugins/available/python.plugin.bash +++ b/plugins/available/python.plugin.bash @@ -8,3 +8,24 @@ else alias http='python -m SimpleHTTPServer' fi +function pyedit() { + about 'opens python module in your EDITOR' + param '1: python module to open' + example '$ pyedit requests' + group 'python' + + xpyc=`python -c "import sys; stdout = sys.stdout; sys.stdout = sys.stderr; import $1; stdout.write($1.__file__)"` + + if [ "$xpyc" == "" ]; then + echo "Python module $1 not found" + return -1 + + elif [[ $xpyc == *__init__.py* ]]; then + xpydir=`dirname $xpyc`; + echo "$EDITOR $xpydir"; + $EDITOR "$xpydir"; + else + echo "$EDITOR ${xpyc%.*}.py"; + $EDITOR "${xpyc%.*}.py"; + fi +}