##// END OF EJS Templates
don't offer subcommands after a dash option
Julian Taylor -
Show More
@@ -1,85 +1,89 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 core.shellapp "shell_flags.keys()" "--"
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 break
34 elif [[ ${i} == "--"* ]]; then
35 mode="nosubcommand"
36 break
33 37 fi
34 38 done
35 39
36 40 if [[ ${cur} == -* ]]; then
37 41 if [[ $mode == "notebook" ]]; then
38 42 _ipython_get_flags notebook
39 43 opts=$"${opts} ${baseopts}"
40 44 elif [[ $mode == "qtconsole" ]]; then
41 45 _ipython_get_flags qtconsole
42 46 opts="${opts} ${baseopts}"
43 47 elif [[ $mode == "console" ]]; then
44 48 _ipython_get_flags console
45 49 elif [[ $mode == "kernel" ]]; then
46 50 _ipython_get_flags kernel
47 51 opts="${opts} ${baseopts}"
48 52 elif [[ $mode == "profile" ]]; then
49 53 opts="list create"
50 54 elif [[ $mode == "locate" ]]; then
51 55 opts=""
52 56 else
53 57 opts=$baseopts
54 58 fi
55 59 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
56 60 return 0
57 61 elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then
58 62 _ipython_get_flags core.shellapp InteractiveShellApp.pylab.values
59 63 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
60 64 elif [[ ${prev} == "--profile"* ]]; then
61 65 if [ -z "$__ipython_complete_profiles" ]; then
62 66 __ipython_complete_profiles=$(cat <<EOF | python -
63 67 try:
64 68 import IPython.core.profileapp
65 69 for k in IPython.core.profileapp.list_bundled_profiles():
66 70 print "%s" % k,
67 71 p = IPython.core.profileapp.ProfileList()
68 72 for k in IPython.core.profileapp.list_profiles_in(p.ipython_dir):
69 73 print "%s" % k,
70 74 except:
71 75 pass
72 76 EOF
73 77 )
74 78 fi
75 79 COMPREPLY=( $(compgen -W "${__ipython_complete_profiles}" -- ${cur}) )
76 80 else
77 81 if [ -z "$mode" ]; then
78 82 COMPREPLY=( $(compgen -f -W "${subcommands}" -- ${cur}) )
79 83 else
80 84 COMPREPLY=( $(compgen -f -- ${cur}) )
81 85 fi
82 86 fi
83 87
84 88 }
85 89 complete -o default -F _ipython ipython
General Comments 0
You need to be logged in to leave comments. Login now