ipython-completion.bash
106 lines
| 3.3 KiB
| text/x-sh
|
BashLexer
Julian Taylor
|
r8292 | # load with: . ipython-completion.bash | ||
_ipython_get_flags() | ||||
{ | ||||
local url=$1 | ||||
local var=$2 | ||||
local dash=$3 | ||||
if [[ "$url $var" == $__ipython_complete_last ]]; then | ||||
opts=$__ipython_complete_last_res | ||||
return | ||||
fi | ||||
Julian Taylor
|
r8343 | # pylab and profile don't need the = and the | ||
# version without simplifies the special cased completion | ||||
opts=$(ipython ${url} --help-all | grep -E "^-{1,2}[^-]" | sed -e "s/<.*//" -e "s/[^=]$/& /" -e "s/^--pylab=$//" -e "s/^--profile=$/--profile /") | ||||
Julian Taylor
|
r8292 | __ipython_complete_last="$url $var" | ||
__ipython_complete_last_res="$opts" | ||||
} | ||||
_ipython() | ||||
{ | ||||
local cur=${COMP_WORDS[COMP_CWORD]} | ||||
local prev=${COMP_WORDS[COMP_CWORD - 1]} | ||||
local subcommands="notebook qtconsole console kernel profile locate" | ||||
local opts="" | ||||
if [ -z "$__ipython_complete_baseopts" ]; then | ||||
Julian Taylor
|
r8338 | _ipython_get_flags baseopts | ||
Julian Taylor
|
r8292 | __ipython_complete_baseopts="${opts}" | ||
fi | ||||
local baseopts="$__ipython_complete_baseopts" | ||||
local mode="" | ||||
for i in "${COMP_WORDS[@]}"; do | ||||
[ "$cur" = "$i" ] && break | ||||
if [[ ${subcommands} == *${i}* ]]; then | ||||
mode="$i" | ||||
Julian Taylor
|
r8337 | break | ||
elif [[ ${i} == "--"* ]]; then | ||||
mode="nosubcommand" | ||||
break | ||||
Julian Taylor
|
r8292 | fi | ||
done | ||||
Julian Taylor
|
r8338 | if [[ $mode == "profile" ]]; then | ||
opts="list create" | ||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||||
elif [[ ${cur} == -* ]]; then | ||||
Julian Taylor
|
r8292 | if [[ $mode == "notebook" ]]; then | ||
Julian Taylor
|
r8336 | _ipython_get_flags notebook | ||
Julian Taylor
|
r8292 | opts=$"${opts} ${baseopts}" | ||
elif [[ $mode == "qtconsole" ]]; then | ||||
Julian Taylor
|
r8336 | _ipython_get_flags qtconsole | ||
Julian Taylor
|
r8292 | opts="${opts} ${baseopts}" | ||
elif [[ $mode == "console" ]]; then | ||||
Julian Taylor
|
r8336 | _ipython_get_flags console | ||
Julian Taylor
|
r8292 | elif [[ $mode == "kernel" ]]; then | ||
Julian Taylor
|
r8336 | _ipython_get_flags kernel | ||
Julian Taylor
|
r8292 | opts="${opts} ${baseopts}" | ||
Julian Taylor
|
r8336 | elif [[ $mode == "locate" ]]; then | ||
opts="" | ||||
Julian Taylor
|
r8292 | else | ||
opts=$baseopts | ||||
fi | ||||
Julian Taylor
|
r8343 | # don't drop the trailing space | ||
local IFS=$'\t\n' | ||||
Julian Taylor
|
r8292 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||||
elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then | ||||
Julian Taylor
|
r8339 | if [ -z "$__ipython_complete_pylab" ]; then | ||
Julian Taylor
|
r8344 | __ipython_complete_pylab=`cat <<EOF | python - | ||
Julian Taylor
|
r8339 | try: | ||
import IPython.core.shellapp as mod; | ||||
for k in mod.InteractiveShellApp.pylab.values: | ||||
Julian Taylor
|
r8343 | print "%s " % k | ||
Julian Taylor
|
r8339 | except: | ||
pass | ||||
EOF | ||||
Julian Taylor
|
r8344 | ` | ||
Julian Taylor
|
r8339 | fi | ||
Julian Taylor
|
r8343 | local IFS=$'\t\n' | ||
Julian Taylor
|
r8339 | COMPREPLY=( $(compgen -W "${__ipython_complete_pylab}" -- ${cur}) ) | ||
Julian Taylor
|
r8336 | elif [[ ${prev} == "--profile"* ]]; then | ||
if [ -z "$__ipython_complete_profiles" ]; then | ||||
Julian Taylor
|
r8344 | __ipython_complete_profiles=`cat <<EOF | python - | ||
Julian Taylor
|
r8336 | try: | ||
import IPython.core.profileapp | ||||
for k in IPython.core.profileapp.list_bundled_profiles(): | ||||
Julian Taylor
|
r8343 | print "%s " % k | ||
Julian Taylor
|
r8336 | p = IPython.core.profileapp.ProfileList() | ||
for k in IPython.core.profileapp.list_profiles_in(p.ipython_dir): | ||||
Julian Taylor
|
r8343 | print "%s " % k | ||
Julian Taylor
|
r8336 | except: | ||
pass | ||||
EOF | ||||
Julian Taylor
|
r8344 | ` | ||
Julian Taylor
|
r8336 | fi | ||
Julian Taylor
|
r8343 | local IFS=$'\t\n' | ||
Julian Taylor
|
r8336 | COMPREPLY=( $(compgen -W "${__ipython_complete_profiles}" -- ${cur}) ) | ||
Julian Taylor
|
r8292 | else | ||
if [ -z "$mode" ]; then | ||||
COMPREPLY=( $(compgen -f -W "${subcommands}" -- ${cur}) ) | ||||
else | ||||
COMPREPLY=( $(compgen -f -- ${cur}) ) | ||||
fi | ||||
fi | ||||
} | ||||
Julian Taylor
|
r8343 | complete -o default -o nospace -F _ipython ipython | ||