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