Merge pull request #2016 from gaelicWizard/plugin/python

plugin/python: OS detection & `shfmt`
pull/2007/head
Noah Gorny 2022-01-07 08:50:07 +02:00 committed by GitHub
commit 931f27ee3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 22 deletions

View File

@ -111,6 +111,7 @@ plugins/available/osx.plugin.bash
plugins/available/percol.plugin.bash plugins/available/percol.plugin.bash
plugins/available/plenv.plugin.bash plugins/available/plenv.plugin.bash
plugins/available/pyenv.plugin.bash plugins/available/pyenv.plugin.bash
plugins/available/python.plugin.bash
plugins/available/rbenv.plugin.bash plugins/available/rbenv.plugin.bash
plugins/available/ruby.plugin.bash plugins/available/ruby.plugin.bash
plugins/available/textmate.plugin.bash plugins/available/textmate.plugin.bash

View File

@ -1,31 +1,32 @@
cite about-plugin # shellcheck shell=bash
about-plugin 'alias "shttp" to SimpleHTTPServer' about-plugin 'alias "shttp" to SimpleHTTPServer'
if [[ "$OSTYPE" == 'linux'* ]] if _command_exists python3; then
then alias shttp='python3 -m http.server'
alias shttp='python2 -m SimpleHTTPServer' elif _command_exists python; then
alias shttp='python -m http.server'
else else
alias shttp='python -m SimpleHTTPServer' _log_warning "Unable to load 'plugin/python' due to being unable to find a working 'python'"
return 1
fi fi
function pyedit() { function pyedit() {
about 'opens python module in your EDITOR' about 'opens python module in your EDITOR'
param '1: python module to open' param '1: python module to open'
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="${xpyc%/*}"
xpydir=`dirname $xpyc`; echo "$EDITOR $xpydir"
echo "$EDITOR $xpydir"; ${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}} "$xpydir"
$EDITOR "$xpydir"; else
else echo "$EDITOR ${xpyc%.*}.py"
echo "$EDITOR ${xpyc%.*}.py"; ${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}} "${xpyc%.*}.py"
$EDITOR "${xpyc%.*}.py"; fi
fi
} }