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