##// END OF EJS Templates
bash completion: profile, history, locate cmds
bash completion: profile, history, locate cmds

File last commit:

r13568:880c1597
r13568:880c1597
Show More
ipython-completion.bash
113 lines | 3.5 KiB | text/x-sh | BashLexer
/ examples / core / ipython-completion.bash
Julian Taylor
add bash completion example...
r8292 # load with: . ipython-completion.bash
Nathan Goldbaum
Completion: Adding preliminary zsh support.
r10204 if [[ -n ${ZSH_VERSION-} ]]; then
autoload -Uz bashcompinit && bashcompinit
fi
Julian Taylor
add bash completion example...
r8292 _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
keep the trailing = of options
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
add bash completion example...
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]}
Paul Ivanov
bash completion: add nbconvert and history subcmds
r13566 local subcommands="notebook qtconsole console kernel profile locate history nbconvert"
Julian Taylor
add bash completion example...
r8292 local opts=""
if [ -z "$__ipython_complete_baseopts" ]; then
Julian Taylor
fix profile subcommand completion
r8338 _ipython_get_flags baseopts
Julian Taylor
add bash completion example...
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
don't offer subcommands after a dash option
r8337 break
elif [[ ${i} == "--"* ]]; then
mode="nosubcommand"
break
Julian Taylor
add bash completion example...
r8292 fi
done
Paul Ivanov
bash completion: profile, history, locate cmds
r13568
if [[ ${cur} == -* ]]; then
Paul Ivanov
bash completion: generalize subcmd completer logic
r13567 case $mode in
"notebook" | "qtconsole" | "console" | "kernel")
_ipython_get_flags $mode
opts=$"${opts} ${baseopts}"
;;
"locate" | "history" | "profile")
_ipython_get_flags $mode
opts=$"${opts}"
;;
*)
opts=$baseopts
esac
Julian Taylor
keep the trailing = of options
r8343 # don't drop the trailing space
local IFS=$'\t\n'
Julian Taylor
add bash completion example...
r8292 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
Paul Ivanov
bash completion: profile, history, locate cmds
r13568 elif [[ $mode == "profile" ]]; then
opts="list create locate"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
elif [[ $mode == "history" ]]; then
opts="trim"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
elif [[ $mode == "locate" ]]; then
opts="profile"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
Julian Taylor
add bash completion example...
r8292 elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then
Julian Taylor
fix pylab completion
r8339 if [ -z "$__ipython_complete_pylab" ]; then
Julian Taylor
replace $() with backticks...
r8344 __ipython_complete_pylab=`cat <<EOF | python -
Julian Taylor
fix pylab completion
r8339 try:
import IPython.core.shellapp as mod;
for k in mod.InteractiveShellApp.pylab.values:
Julian Taylor
keep the trailing = of options
r8343 print "%s " % k
Julian Taylor
fix pylab completion
r8339 except:
pass
EOF
Julian Taylor
replace $() with backticks...
r8344 `
Julian Taylor
fix pylab completion
r8339 fi
Julian Taylor
keep the trailing = of options
r8343 local IFS=$'\t\n'
Julian Taylor
fix pylab completion
r8339 COMPREPLY=( $(compgen -W "${__ipython_complete_pylab}" -- ${cur}) )
Julian Taylor
use help-all to get all options and add profile specializations
r8336 elif [[ ${prev} == "--profile"* ]]; then
if [ -z "$__ipython_complete_profiles" ]; then
Julian Taylor
replace $() with backticks...
r8344 __ipython_complete_profiles=`cat <<EOF | python -
Julian Taylor
use help-all to get all options and add profile specializations
r8336 try:
import IPython.core.profileapp
for k in IPython.core.profileapp.list_bundled_profiles():
Julian Taylor
keep the trailing = of options
r8343 print "%s " % k
Julian Taylor
use help-all to get all options and add profile specializations
r8336 p = IPython.core.profileapp.ProfileList()
for k in IPython.core.profileapp.list_profiles_in(p.ipython_dir):
Julian Taylor
keep the trailing = of options
r8343 print "%s " % k
Julian Taylor
use help-all to get all options and add profile specializations
r8336 except:
pass
EOF
Julian Taylor
replace $() with backticks...
r8344 `
Julian Taylor
use help-all to get all options and add profile specializations
r8336 fi
Julian Taylor
keep the trailing = of options
r8343 local IFS=$'\t\n'
Julian Taylor
use help-all to get all options and add profile specializations
r8336 COMPREPLY=( $(compgen -W "${__ipython_complete_profiles}" -- ${cur}) )
Julian Taylor
add bash completion example...
r8292 else
if [ -z "$mode" ]; then
COMPREPLY=( $(compgen -f -W "${subcommands}" -- ${cur}) )
else
COMPREPLY=( $(compgen -f -- ${cur}) )
fi
fi
}
Julian Taylor
keep the trailing = of options
r8343 complete -o default -o nospace -F _ipython ipython