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