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