##// END OF EJS Templates
add bash completion example...
Julian Taylor -
Show More
@@ -0,0 +1,73 b''
1 # load with: . ipython-completion.bash
2
3 _ipython_get_flags()
4 {
5 local url=$1
6 local var=$2
7 local dash=$3
8 if [[ "$url $var" == $__ipython_complete_last ]]; then
9 opts=$__ipython_complete_last_res
10 return
11 fi
12 opts=$(cat <<EOF | python -
13 try:
14 import IPython.${url} as mod;
15 for k in mod.${var}:
16 print "${dash}%s" % k,
17 except:
18 pass
19 EOF
20 )
21 __ipython_complete_last="$url $var"
22 __ipython_complete_last_res="$opts"
23 }
24
25 _ipython()
26 {
27 local cur=${COMP_WORDS[COMP_CWORD]}
28 local prev=${COMP_WORDS[COMP_CWORD - 1]}
29 local subcommands="notebook qtconsole console kernel profile locate"
30 local opts=""
31 if [ -z "$__ipython_complete_baseopts" ]; then
32 _ipython_get_flags core.shellapp "shell_flags.keys()" "--"
33 __ipython_complete_baseopts="${opts}"
34 fi
35 local baseopts="$__ipython_complete_baseopts"
36 local mode=""
37 for i in "${COMP_WORDS[@]}"; do
38 [ "$cur" = "$i" ] && break
39 if [[ ${subcommands} == *${i}* ]]; then
40 mode="$i"
41 fi
42 done
43
44 if [[ ${cur} == -* ]]; then
45 if [[ $mode == "notebook" ]]; then
46 _ipython_get_flags frontend.html.notebook.notebookapp notebook_flags "--"
47 opts=$"${opts} ${baseopts}"
48 elif [[ $mode == "qtconsole" ]]; then
49 _ipython_get_flags frontend.qt.console.qtconsoleapp qt_flags "--"
50 opts="${opts} ${baseopts}"
51 elif [[ $mode == "console" ]]; then
52 _ipython_get_flags frontend.terminal.console.app frontend_flags "--"
53 elif [[ $mode == "kernel" ]]; then
54 _ipython_get_flags zmq.kernelapp "kernel_flags.keys()" "--"
55 opts="${opts} ${baseopts}"
56 else
57 opts=$baseopts
58 fi
59 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
60 return 0
61 elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then
62 _ipython_get_flags core.shellapp InteractiveShellApp.pylab.values
63 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
64 else
65 if [ -z "$mode" ]; then
66 COMPREPLY=( $(compgen -f -W "${subcommands}" -- ${cur}) )
67 else
68 COMPREPLY=( $(compgen -f -- ${cur}) )
69 fi
70 fi
71
72 }
73 complete -o default -F _ipython ipython
General Comments 0
You need to be logged in to leave comments. Login now