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