plugins/python: code style improvements
Use shell functionality to avoid invoking external binaries, and quote some stuff. Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.pull/2016/head
parent
2e51e92699
commit
dd911f1256
|
|
@ -1,11 +1,12 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'alias "shttp" to SimpleHTTPServer'
|
about-plugin 'alias "shttp" to SimpleHTTPServer'
|
||||||
|
|
||||||
if [[ "$OSTYPE" == 'linux'* ]]
|
if _command_exists python2; then
|
||||||
then
|
alias shttp='python2 -m SimpleHTTPServer'
|
||||||
alias shttp='python2 -m SimpleHTTPServer'
|
elif _command_exists python
|
||||||
|
alias shttp='python -m SimpleHTTPServer'
|
||||||
else
|
else
|
||||||
alias shttp='python -m SimpleHTTPServer'
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function pyedit() {
|
function pyedit() {
|
||||||
|
|
@ -14,18 +15,18 @@ function pyedit() {
|
||||||
example '$ pyedit requests'
|
example '$ pyedit requests'
|
||||||
group 'python'
|
group 'python'
|
||||||
|
|
||||||
xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"`
|
xpyc="$(python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)")"
|
||||||
|
|
||||||
if [[ "$xpyc" == "" ]]; then
|
if [[ "$xpyc" == "" ]]; then
|
||||||
echo "Python module $1 not found"
|
echo "Python module $1 not found"
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
elif [[ $xpyc == *__init__.py* ]]; then
|
elif [[ "$xpyc" == *__init__.py* ]]; then
|
||||||
xpydir=`dirname $xpyc`;
|
xpydir="${xpyc%/*}";
|
||||||
echo "$EDITOR $xpydir";
|
echo "$EDITOR $xpydir";
|
||||||
$EDITOR "$xpydir";
|
${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}} "$xpydir";
|
||||||
else
|
else
|
||||||
echo "$EDITOR ${xpyc%.*}.py";
|
echo "$EDITOR ${xpyc%.*}.py";
|
||||||
$EDITOR "${xpyc%.*}.py";
|
${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}} "${xpyc%.*}.py";
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue