Add a pyedit command thanks to @srossross

pull/279/head
Travis Swicegood 2014-03-26 09:58:24 -05:00
parent 1ec1c938b1
commit ee793d4cce
1 changed files with 21 additions and 0 deletions

View File

@ -8,3 +8,24 @@ else
alias http='python -m SimpleHTTPServer' alias http='python -m SimpleHTTPServer'
fi 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
}